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)
X-axis grouping in the line chart
JayanthiS
<p>Hi,</p>
<p>I would like to have a line chart with an overview of time periods grouped by months. I have a dataset with columns (startdate(DATETIME), enddate(DATETIME), time period desc(DATETIME), value(FLOAT), indx name (string)).</p>
<p>Taking the time period desc in x-axis (as month data) and the value in y-axis and optional grouping as indx name. The x-axis should get grouped in order to display all the data points between each Time period.</p>
<p> </p>
<p>for example,<br>
If the user selects a 05/31/16 startdate and to plot 5 Years TP, the axis should like (please check the attachment<strong> plot1</strong>)</p>
<p> </p>
<p>the x-axis label would be,</p>
<p>05/16 05/15 05/14 05/13 05/12 05/11</p>
<p> </p>
<p>In-between 05/16 to 05/15 we have 12 data points..so we need to show the 12 data points without x-axis TP (04/16, 03/16,02/16,01/16,12/15,11/15,10/15,09/15,08/15,07/15,06/15).</p>
<p> </p>
<p>Please see the attachment <strong>Plot2 </strong>for reference. Can anyone please help me out in grouping the x-axis label as per the expectations.</p>
Find more posts tagged with
Comments
pricher
<p>Hi,</p>
<p> </p>
<p>Based on your screenshots, I assume you're doing this with Open Source BIRT. If so, there are two ways you can do this:</p>
<p> </p>
<p>1. without scripting</p>
<p> </p>
<p>In Select Data, click on Edit Group and Sorting and select Months as the Grouping Unit;</p>
<p>
JayanthiS
<p>Hi Pricher,</p>
<p>Thanks for your quick response, The solution works fine for me. I have a question like how do I set the label interval dynamically using a script and at the same time need to hide the ticks for the label interval set. Could you please help me out on this?</p>
pricher
<p>Hi,</p>
<p> </p>
<p>What do you mean exactly by "set the label interval dynamically"? Do you mean change the grouping dynamically (e.g. by year or month or quarter)? Or do you mean if grouped by month, show labels only for year (the example I sent you already), or every 3 months, or every 6 months?</p>
<p> </p>
<p>As for hiding ticks, I believe it's all or nothing. I couldn't find an API call to hide ticks selectively.</p>
<p> </p>
<p>P.</p>
JayanthiS
<p>Hi Pricher,</p>
<p> </p>
<p>Sorry for replying late.</p>
<p> </p>
<p>The logic for hiding the x-axis label works fine (I mean if I grouped by month, show the x-axis labels only for year/every 3 months/every 6 months), but at the same time I would like to hide the ticks for the same..Is there any work around available. It would be great if you could share some idea on this.</p>
<p> </p>
<p>Thanks.</p>
pricher
<p>Hi,</p>
<p> </p>
<p>As I said in my previous post, I could not find an API call to hide the ticks selectively.</p>
<p> </p>
<p>P.</p>
vijayshankar245
<blockquote class="ipsBlockquote" data-author="pricher" data-cid="144304" data-time="1466081577">
<div>
<p>Hi,</p>
<p> </p>
<p>What do you mean exactly by "set the label interval dynamically"? Do you mean change the grouping dynamically (e.g. by year or month or quarter)? Or do you mean if grouped by month, show labels only for year (the example I sent you already), or every 3 months, or every 6 months?</p>
<p> </p>
<p>As for hiding ticks, I believe it's all or nothing. I couldn't find an API call to hide ticks selectively.</p>
<p> </p>
<p>P.</p>
</div>
</blockquote>
<p>Hi Pricher</p>
<p>Could you able to help me in dynamically change the x axis grouping by last 4 months wherever the report gets generated. I'm using bar chart in my report. BIRT version is 4.4.0.</p>
<p>I want to display x-axis lables as below,</p>
<p>Mar16 Apr16 May16 Jun16..</p>
pricher
<p>Hi,</p>
<p> </p>
<p>If you want to get the data for the last four months, you should filter your query to return data only for the last four months. This has nothing to do with grouping.</p>
<p> </p>
<p>P.</p>
rajkishore
<p>Try this for dynamic x-axis grouping.</p>
<pre class="_prettyXprint">
importPackage( Packages. org.eclipse.birt.chart.model);importPackage (Packages.org.eclipse.birt.chart.model.attribute );cht = reportContext.getDesignHandle().findElement("mychart");mychart = cht.getReportItem().getProperty( "chart.instance" );xAxis =mychart.getAxes().get(0);xSeriesDef = xAxis.getSeriesDefinitions().get(0);xGrouping = xSeriesDef.getGrouping();xGrouping.setGroupingUnit(GroupingUnitType.MONTHS_LITERAL); // You can also use WEEKS_LITERAL, DAYS_LITERAL, YEARS_LITERAL</pre>
shamo
<p>Do something like this on you dataset in the where clause. some thing like datefield between add_months( current_Date, -8) and add_months(current_Date,-4) or with same concept but filter on the chart with the date field between min value using datefunctions to add months.</p>
vijayshankar245
<blockquote class="ipsBlockquote" data-author="shamo" data-cid="144599" data-time="1468500513">
<div>
<p>Do something like this on you dataset in the where clause. some thing like datefield between add_months( current_Date, -8) and add_months(current_Date,-4) or with same concept but filter on the chart with the date field between min value using datefunctions to add months.</p>
</div>
</blockquote>
<p>Thanks.</p>
<p> </p>
<p>Have added filter to get data only for the last 4 months. It worked.</p>
vijayshankar245
<blockquote class="ipsBlockquote" data-author="pricher" data-cid="144590" data-time="1468414481">
<div>
<p>Hi,</p>
<p> </p>
<p>If you want to get the data for the last four months, you should filter your query to return data only for the last four months. This has nothing to do with grouping.</p>
<p> </p>
<p>P.</p>
</div>
</blockquote>
<p><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">I have a bar chart with an overview of time periods grouped by weeks. my requirement is show data for the last 6 weeks. have added a filter in the chart to show only last 6 weeks. The chart groups data from sunday to saturday of a particular week and shows as sunday's date. please check the attached image, i have filtered the date from 20-06-2016 to 31-07-2016. </span></p>
<p>I need the chart to show values like 26th june,03rd july,10th july, 17th july,24th july, 31st july.</p>
<p><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">But the graph starts value from 19th june. ideally it should start from 26th june, since i have given start date as 20th june, it should calculate the values from 20- 25th june and show the sum in 26th june 2016 and so on. Please help how do i change the calculation here.</span></p>
pricher
<p>Hi,</p>
<p> </p>
<p>If you want the total for the week to show on the following Sunday in your chart, simply add a computed column in your data set that adds one week to the original date, and use that date as the X-Axis grouping. So, if the original date in your data set is MyDate, add a new computed column named MyDatePlusOneWeek using the following expression:</p>
<pre class="_prettyXprint _lang-">
BirtDateTime.addWeek(row["MyDate"],1)
</pre>
<p>The filter to get the last 6 weeks of data should still happen on the original date.</p>
<p> </p>
<p>I am attaching an example using a CSV file.</p>
<p> </p>
<p>Hope this helps,</p>
<p> </p>
<p>P.</p>
vijayshankar245
<blockquote class="ipsBlockquote" data-author="pricher" data-cid="144798" data-time="1470232633">
<div>
<p>Hi,</p>
<p> </p>
<p>If you want the total for the week to show on the following Sunday in your chart, simply add a computed column in your data set that adds one week to the original date, and use that date as the X-Axis grouping. So, if the original date in your data set is MyDate, add a new computed column named MyDatePlusOneWeek using the following expression:</p>
<pre class="_prettyXprint _lang-">
BirtDateTime.addWeek(row["MyDate"],1)
</pre>
<p>The filter to get the last 6 weeks of data should still happen on the original date.</p>
<p> </p>
<p>I am attaching an example using a CSV file.</p>
<p> </p>
<p>Hope this helps,</p>
<p> </p>
<p>P.</p>
</div>
</blockquote>
<p>Thanks a lot Pierre.</p>
<p>The above solution works. but shows last 7 weeks even after giving filter to show only 6 weeks data. I need the chart to show upto 31st july but the chart is showing till 07th august. since we are giving filter upto 31st july, the data on 31st july is reflecting on 7th august. If you see the screenshot of your example, value 1 is showing on 7th august.</p>
<p> </p>
<p>I have tried reducing the filter to 30th july. but the chart shows only 5 weeks till 24th july. Is there any other way to hide the last value or remove the last entry in the chart?</p>
pricher
<p>Hi,</p>
<p> </p>
<p>Change the expression in the MyDataPlusOneWeek computed column to add 6 days instead of a week:</p>
<pre class="_prettyXprint _lang-">
BirtDateTime.addDay(row["MyDate"],6)
</pre>
<p>P.</p>
vijayshankar245
<blockquote class="ipsBlockquote" data-author="pricher" data-cid="144813" data-time="1470321894">
<div>
<p>Hi,</p>
<p> </p>
<p>Change the expression in the MyDataPlusOneWeek computed column to add 6 days instead of a week:</p>
<pre class="_prettyXprint _lang-">
BirtDateTime.addDay(row["MyDate"],6)
</pre>
<p>P.</p>
</div>
</blockquote>
<p>Thanks a lot Pierre.</p>