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)
setting number of plots on a line chart
Ben Sztucki
<p>Hi Guys hope you can help with my problem, </p>
<p> </p>
<p>I currently have a number of line charts in a report and they have start and end time parameters. So far I can set the time period in which i want an average to be created. e.g for the last 24 hours of data it will have one average per hour.</p>
<p> </p>
<p>The problem is when I change the time scale to some larger like a week. By doing this I then have too many nodes on my line chart. Is there a way that I can change how the average is calculated depending on the time period. Ideally it would be something like below:</p>
<p> </p>
<p>24 hour period = 1 per hour</p>
<p>7day period = 1 per 6 hours</p>
<p>30 day period = 1 per day </p>
<p> </p>
<p>If you need any more information please let me know. </p>
<p> </p>
<p>Thanks, </p>
<p> </p>
<p>Ben </p>
Find more posts tagged with
Comments
GLO_FR
<p>Hi,</p>
<p> </p>
<p>If I understand well, you want to change the grouping scale of your chart dynamically. Thats right ?</p>
Ben Sztucki
<p>I do yes, sorry I'm not very good at explaining myself. </p>
<p> </p>
<p>Thanks
</p>
GLO_FR
<p>Check this example.</p>
<p> </p>
<p><a data-ipb='nomediaparse' href='
http://developer.actuate.com/community/forum/index.php?/files/file/679-change-birt-chart-interval-type-at-runtime/'>http://developer.actuate.com/community/forum/index.php?/files/file/679-change-birt-chart-interval-type-at-runtime/</a></p>
;
<p> </p>
<p> </p>
Ben Sztucki
<p>I can see how this works and I can see how the grouping scale changes.</p>
<p> </p>
<p>It may make more sense if I explain how the report works. </p>
<p> </p>
<p>I am currently using Reportlets to display my line charts in a dashboard.</p>
<p> </p>
<p>At the moment I have start and end parameters which allow the user to select the time period that they wish to look at and I have set the default to be the last 24 hours. </p>
<p> </p>
<p>As it is the last 24 hours the current interval for the plotting is 1hour. This means that there should be 24 plotted points on my chart.</p>
<p> </p>
<p>When the time period is increased to two days there will then be 48 plotted points on the chart. As the time scale increases there will be more and more plotted points on the chart which will start to look silly.</p>
<p> </p>
<p>So what I would like to do is change the grouping so that the number of plotted points will stay around the 24-30 mark and look nice. This means that even if we select 6months worth of data there will still be 24-30 plotted points on the chart.</p>
<p> </p>
<p>Is there a way to do this???</p>
<p> </p>
<p>Thank you for any help that you can provide</p>
<p> </p>
<p>Ben
</p>
GLO_FR
<p>Maybe the easiest way is to "limit" the number of points directly in your DS.</p>
<p> </p>
<p>You can do this.</p>
<p>1) Count the numer of line of your DS</p>
<p>2) Divide this number by the number of points that you want in your chart (for instance you have 50 lines and you only want 25 points, so the ration is <strong>2</strong>)</p>
<p>3) create a computed field in your DS and make a "rownumber modulo <your ratio value>" (in our example rownumber % 2)</p>
<p>4) only use in your chart, the line with "0" in the computed column, so you will only have 25 points in your chart</p>
<p> </p>
<p>... that's a way to do it</p>
Ben Sztucki
<p>we can't do it in the DS directly as it changes dynamically. Also we are dealing with a DB that will have 500,000+ records depending on the time period that is selected. Another reason that we don't want to do it in the dataset is that we want users to have access to the raw data.</p>
GLO_FR
<p>Ok,</p>
<p>if you use <span style="font-size:14px;">the example in the devshare, instead of changing the scale (day/month/year), if you stay in hours and change the interval, does it work ? (i.e. 1 day, interval=1, 2 day interval=2....).</span></p>
<p> </p>
<p>Limiting the number in the DS or changing the scale/interval in the chart seems, for me, to be the only way to solve your problem.</p>
Ben Sztucki
<div>if (params["IntervalParam"].equals("Days")) {</div>
<div> xGrouping.setGroupingUnit(GroupingUnitType.DAYS_LITERAL);</div>
<div> </div>
<div>where in this would i set the interval ? </div>
Ben Sztucki
<p>Also how do i set the grouping to provide an average?? </p>
GLO_FR
<p>This is for the grouping unit</p>
<pre class="_prettyXprint">
xGrouping.setGroupingUnit(GroupingUnitType.DAYS_LITERAL)</pre>
<p><span style="font-size:14px;">This is for the grouping interval</span></p>
<pre class="_prettyXprint">
xGrouping.setGroupingInterval(1)</pre>
<blockquote class="ipsBlockquote" data-author="Ben Sztucki" data-cid="131616" data-time="1414165118">
<div>
<p>Also how do i set the grouping to provide an average?? </p>
</div>
</blockquote>
<p>I guess this has to be set on the Y axis</p>
Ben Sztucki
<p>It doesn't have to be set on the y-axis when you set the grouping on the x-axis of a report you have a number of grouping attributes that you can set which include:</p>
<p> </p>
<p>* type: DateTime</p>
<p>* unit: Hours</p>
<p>* Interval: 1</p>
<p>Aggregate Expression: Average</p>
<p> </p>
<p>In this instance i want to set the aggregate expression to average pragmatically in JavaScript. By doing this I will then be able to have an average per what ever time period I Choose. </p>
<p> </p>
<p> </p>
<p>My next question is that in an example the interval at which the chart is based is calculated using the following snippet of code: </p>
<p> </p>
<div>if (params["IntervalParam"].equals("Last24Hours")) {</div>
<div> xGrouping.setGroupingUnit(GroupingUnitType.HOURS_LITERAL);</div>
<div> xGrouping.setGroupingInterval(1);</div>
<div> </div>
<div>What I would like to do is change the if statement by having two parameters, 'start' and 'end' and then subtract them from each other which will then give me a number of days. This will then act as the variable in which I will calculate how the intervals are calculated.</div>
GLO_FR
<p>To set the aggregation function, try this </p>
<pre class="_prettyXprint _lang-auto _linenums:0">
xGrouping.setAggregateExpression("Average")</pre>
<p> <br>
To calculate a difference between 2 dates, you can use Birt date functions like</p>
<pre class="_prettyXprint _lang-auto _linenums:0">
BirtDateTime.diffDay(<start date>, <end date>)</pre>
Ben Sztucki
<p>I want to have the java script work like this: </p>
<p> </p>
<div>importPackage( Packages. org.eclipse.birt.chart.model);</div>
<div>importPackage( Packages. org.eclipse.birt.chart.model.attribute);</div>
<div> </div>
<div>rptDesignHandle = reportContext.getReportRunnable().designHandle.getDesignHandle();</div>
<div>chart = rptDesignHandle.findElement("NewChart");</div>
<div>item = chart.getReportItem();</div>
<div>cm = item.getProperty("chart.instance");</div>
<div> </div>
<div>xAxis = cm.getAxes( ).get( 0 );</div>
<div>xSeriesDef = xAxis.getSeriesDefinitions( ).get( 0 );</div>
<div>xGrouping = xSeriesDef.getGrouping( );</div>
<div> </div>
<div> </div>
<div>diff = BirtDateTime.diffDay(<params["start"]>, <params["end"]>);</div>
<div> </div>
<div>if (diff <= 1) {</div>
<div> xGrouping.setGroupingUnit(GroupingUnitType.HOURS_LITERAL); //Getting a syntax error here </div>
<div> xGrouping.setGroupingInterval( 1 );</div>
<div> </div>
<div>} else if (diff >=1 && <=7 ) {</div>
<div> xGrouping.setGroupingUnit(GroupingUnitType.HOURS_LITERAL);</div>
<div> xGrouping.setGroupingInterval( 6 );</div>
<div> </div>
<div>} else if (diff >=7 && <=30) {</div>
<div> xGrouping.setGroupingUnit(GroupingUnitType.DAYS_LITERAL);</div>
<div> xGrouping.setGroupingInterval( 1 );</div>
<div> </div>
<div>}</div>
<div> </div>
<div>Am I calculating the time difference here correctly as I am getting a syntax error where I commented.</div>
GLO_FR
<p>You have to calculate your diff in a report variable (see screenshot) and use it with </p>
<pre class="_prettyXprint">
vars["myDiff"]</pre>
<p>Otherwise you have to calcultate it in JS, and that not so simple</p>
<p><a data-ipb='nomediaparse' href='
http://www.htmlgoodies.com/html5/javascript/calculating-the-difference-between-two-dates-in-javascript.html#fbid=_mUEf--JXsr'>http://www.htmlgoodies.com/html5/javascript/calculating-the-difference-between-two-dates-in-javascript.html#fbid=_mUEf--JXsr</a></p>
;
Ben Sztucki
<p><a data-ipb='nomediaparse' href='
http://jsfiddle.net/zANNt/564/'>http://jsfiddle.net/zANNt/564/</a></p>
;
<p> </p>
<p>This link shows how to work out the time difference of two dates in days in 5 lines of code.</p>
<p> </p>
<p>The problem is that I cannot incorporate this into Birt without it giving me errors when I try to run the report. As I see it I don't need to use a variable because i can do it in javascript quite effectively using the code in the link. The problem that I am having is that i cannot link in the parameters into it properly so that the difference can be calculated. </p>
Ben Sztucki
<p>Also even if i set the variable diff to 1 and use:</p>
<p> </p>
<div>
<div>if (vars["diff"].value <= 1) {</div>
<div> xGrouping.setGroupingUnit(GroupingUnitType.HOURS_LITERAL);</div>
<div> xGrouping.setGroupingInterval(1);</div>
<div> </div>
<div>}else {</div>
<div> xGrouping.setGroupingUnit(GroupingUnitType.HOURS_LITERAL);</div>
<div> xGrouping.setGroupingInterval(1);</div>
<div>}</div>
</div>
<div> </div>
<div>It still doesn't run. I have also been suing js lint to double check my code. </div>