Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Line of Best Fit(Trend Line)
bachi
Hi,
I have designed a report with scatter chart.
My X-axis 24 hour time and Y-axis with values 0 to 20.
I need to show best fit average line in the graph. I was looking at birt options I could not found one.
Is there anyway that I can show this line on my graph?
Thanks for your help in advance.
I am using latest version of birt in eclipse.
Find more posts tagged with
Comments
kclark
On the select data screen choose add series from the drop down, then select the sigma drop down on the axis you want to display the average data. From here you can aggregate the average value.
Are you wanting a best fit line that isn't straight across?
bachi
Hi,
Thanks for the reply. I am attaching the sample which explains what I am trying to do.
kclark
Thanks for the info! What version of BIRT are you running?
bachi
I am using latest version(4.x) of birt in eclipse.
kclark
Checkout <a class='bbc_url' href='
http://www.birt-exchange.org/org/devshare/designing-birt-reports/1548-creating-a-line-of-best-fit-line-in-a-scatter-chart/'>this
devshare</a> it should show you how to do it. It computes the average for the first set of data and then the second set, from that it plots the best fit line.
bachi
Hi,
Thanks for the report with example.
Mine is 24 hour time on x-axis and float on y-axis. When I use integer that works fine but not with the time.
Please see the attached pdf
kclark
I would think if you are using the 24 hour time format that it should work ok for you. Can you post the rptdesign for me to look at?
bachi
Hi,
I have removed the datasource.
Please find the attached rpdesign.
Please send me your email I can attach rptdesign to it.
Thanks.
kclark
There is a new devshare that you can take a look at that takes time/date into account instead of integers -- <a class='bbc_url' href='
http://www.birt-exchange.org/org/devshare/designing-birt-reports/1551-creating-a-line-of-best-fit-line-in-a-scatter-chart-when-xaxis-field-is-a-date/'>http://www.birt-exchange.org/org/devshare/designing-birt-reports/1551-creating-a-line-of-best-fit-line-in-a-scatter-chart-when-xaxis-field-is-a-date/</a>
, let me know if this works for you.
bachi
Hi,
That works for date great. I am trying to get 24 hour time on X-axis then it does not work.
Thanks,
kclark
I got it to work with a little help from Michael with this code<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage( Packages.org.eclipse.birt.chart.util);
firstHalfXTotal = 0;
firstHalfYTotal = 0;
secondHalfXTotal = 0;
secondHalfYTotal = 0;
numFirstHalfValues = 0;
numSecondHalfValues = 0;
function afterDataSetFilled( series, dataSet, icsc )
{
if (series.getSeriesIdentifier() == ""){
df = new java.text.SimpleDateFormat("MM-dd-yyyy HH:mm:ss");
xvals = dataSet.getValues();
numValues = xvals.length;
//find num data points below half point
for(i=0;i<numValues;i++){
if(df.parse(xvals[i]).getHours() < 12){
numFirstHalfValues++;
}
}
numSecondHalfValues = numValues - numFirstHalfValues;
//find first half average x point
for(i=0;i<numFirstHalfValues;i++){
firstHalfXTotal = firstHalfXTotal + df.parse(xvals[i]).getHours();
}
firstHalfAvgX = firstHalfXTotal / numFirstHalfValues;
//find second half average x point
for(i=numFirstHalfValues;i<numValues;i++){
secondHalfXTotal = secondHalfXTotal + df.parse(xvals[i]).getHours();
}
secondHalfAvgX = secondHalfXTotal / numSecondHalfValues;
}
if(series.getSeriesIdentifier() == "ValueSeries"){
yvals = dataSet.getValues();
//find first half average y point
for(i=0;i<numFirstHalfValues;i++){
firstHalfYTotal = firstHalfYTotal + parseFloat(yvals[i]);
}
firstHalfAvgY = firstHalfYTotal / numFirstHalfValues;
//find second half average y point
for(i=numFirstHalfValues;i<numValues;i++){
secondHalfYTotal = secondHalfYTotal + parseFloat(yvals[i]);
}
secondHalfAvgY = secondHalfYTotal / numSecondHalfValues;
}
if(series.getSeriesIdentifier() == "LineOfBestFit"){
lobfvals = dataSet.getValues();
//compute slope and y-intercept of best fit line
slope = (secondHalfAvgY - firstHalfAvgY) / (secondHalfAvgX - firstHalfAvgX);
yintercept = firstHalfAvgY - slope * firstHalfAvgX;
//set new values for line of best fit series
for(i=0;i<numValues;i++){
lobfvals[i] = slope * df.parse(xvals[i]).getHours() + yintercept;
}
}
}
</pre>
<br />
I've also attached the rptdesign for you to take a look at
bachi
Hi,
Sorry for the late reply.
That works like charm.
Thanks for your help.
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. Also, my BIRT version is 2.6.1. So, i cannot use the one provided above. Please help me out.
Thanks in Advance,
Akshatha
monica@123
<p>Hi,</p>
<p>I have used the script and my output is different than trend line of the excel.</p>
<p> </p>
<p>On my Birt report, trend line shows UP trend where as in excel it shows DOWN trend.</p>
<p>Kindly find attached image for the same. </p>
<p> </p>
<p>Birt Image Link : <a data-ipb='nomediaparse' href='
https://s29.postimg.org/vzdioad1z/birt.png'>https://s29.postimg.org/vzdioad1z/birt.png</a></p>
;
<p> </p>
<p>Excel Image Link :<a data-ipb='nomediaparse' href='
https://s27.postimg.org/sejrk736b/excel.png'>https://s27.postimg.org/sejrk736b/excel.png</a></p>
;