Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Line of best fit for bar charts
akshatha_k
Hi,
I have to generate a 'Line of best fit' for a Bar/line chart. And i have x-axis values as string and y-axis values as number(int). Also, my BIRT version is 2.6.1. Please help me out.
Thanks in Advance,
Akshatha
Find more posts tagged with
Comments
mwilliams
Have you seen this post, in the devShare?
http://www.birt-exchange.org/org/devshare/designing-birt-reports/1548-creating-a-line-of-best-fit-line-in-a-scatter-chart/
akshatha_k
Hi,<br />
<br />
Thanks a lot for the quick reply. <br />
<br />
Yes, i have looked into that link. But, in that case we have x-axis values as float. I have my <strong class='bbc'>x-axis value as a string</strong>. Can you help me modify the same for my requirement?<br />
<br />
Also, my BIRT version is 2.6.1<br />
<br />
Regards,<br />
Akshatha
mwilliams
Take a look at this modified report. I created it in BIRT 2.6.1. Rather than dealing with the x-axis value, we just deal with the x-axis value index to create the slope of the line.
akshatha_k
Hi,<br />
<br />
Thank you for your reply again. The report design is working perfectly fine for my requirement but,<strong class='bbc'>with one exception. </strong><br />
<br />
Suppose if the y-axis value is null, the "Line of best Fit" is not generating. <br />
<br />
I'm attaching the <strong class='bbc'>modified report design</strong> in which there is a second chart which depicts this scenario. Please find the attachment for the same.<br />
<br />
Waiting for you reply.<br />
<br />
Regards,<br />
Akshatha
mwilliams
Can you try attaching again? When I try to open the attached file, I get told it has errors that keep it from being opened.
akshatha_k
Hi,
Please find the attachment.
Regards,
Akshatha
mwilliams
Just add a simple check for null values when adding up the y-series values:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
if(series.getSeriesIdentifier() == "ValueSeries2"){
yvals = dataSet.getValues();
//find first half average y point
for(i=0;i<numFirstHalfValues;i++){
if(yvals[i] != null){
firstHalfYTotal = firstHalfYTotal + parseFloat(yvals[i]);
}
}
firstHalfAvgY = firstHalfYTotal / numFirstHalfValues;
//find second half average y point
for(i=numFirstHalfValues;i<numValues;i++){
if(yvals[i] != null){
secondHalfYTotal = secondHalfYTotal + parseFloat(yvals[i]);
}
}
secondHalfAvgY = secondHalfYTotal / numSecondHalfValues;
}
</pre>
<br />
Hope this helps.
akshatha_k
Hi,
That worked perfectly. Thank you for your help.
Regards,
Akshatha
mwilliams
You're welcome! Let me know if you run into any more problems, with this.