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)
Setting different intervals an x-axis
tymhon
Hi, I'm creating a bar chart where x-axis is date and y-axis is time spent on work each day through the chart api. Is there a way to set multiple intervals on x-axis. The reason why I want to do that is because I only want to display the date for start of week or start of month depending on the date range. I try setting the series for x-axis to have empty strings for days I don't want to display the label, but it is still not showing properly. Any help would be greatly appreciated.
Terry
Find more posts tagged with
Comments
Virgil Dodson
Hi Terry,<br />
<br />
Since you are using the Chart APIs to create the report, have you played with setting the grouping unit or interval at runtime? Below is how I did something similar with scripting in a report design but similar code can be used with the Chart API. In this example, I change from days, weeks, months, and years based on user input. I've also uploaded this example to the DevShare at: <a class='bbc_url' href='
http://www.birt-exchange.com/modules/wfdownloads/singlefile.php?cid=2&lid=412'>http://www.birt-exchange.com/modules/wfdownloads/singlefile.php?cid=2&lid=412</a><br
/>
<br />
beforeFactory {<br />
<br />
importPackage( Packages. org.eclipse.birt.chart.model);<br />
importPackage( Packages. org.eclipse.birt.chart.model.attribute);<br />
<br />
rptDesignHandle = reportContext.getReportRunnable().designHandle.getDesignHandle();<br />
chart = rptDesignHandle.findElement("NewChart");<br />
item = chart.getReportItem();<br />
cm = item.getProperty("chart.instance");<br />
<br />
xAxis = cm.getAxes( ).get( 0 );<br />
xSeriesDef = xAxis.getSeriesDefinitions( ).get( 0 );<br />
xGrouping = xSeriesDef.getGrouping( );<br />
//xGrouping.setGroupingInterval( 1 );<br />
<br />
if (params["IntervalParam"].equals("Days")) {<br />
xGrouping.setGroupingUnit(GroupingUnitType.DAYS_LITERAL);<br />
} else if (params["IntervalParam"].equals("Weeks")) {<br />
xGrouping.setGroupingUnit(GroupingUnitType.WEEKS_LITERAL);<br />
} else if (params["IntervalParam"].equals("Months")) {<br />
xGrouping.setGroupingUnit(GroupingUnitType.MONTHS_LITERAL);<br />
} else if (params["IntervalParam"].equals("Years")) {<br />
xGrouping.setGroupingUnit(GroupingUnitType.YEARS_LITERAL);<br />
}<br />
<br />
}
tymhon
Thanks Virgil. Do I have to do it dynamically? I'm wondering if I can actually call setGroupingUnit on the xAxis grouping in the code where I'm generating the chart. I tried it and it seems like changing the grouping unit doesn't change it from the default unit.
Terry
Virgil Dodson
Hi Terry,
I'm not sure I understand this new question. The code above is setting the grouping interval on the x-axis with code. Can you attach your code so we can see the difference?
tymhon
Sorry that I wasn't clear before. Here is the code snippet that I have, which brings up another question too. What format specifier can I use to only display the month of the date (in the case of numDays > 28). Thanks for your help!
GroupingUnitType displayGrouping;
if (numDays <= 7) {
displayGrouping = GroupingUnitType.DAYS_LITERAL;
formatSpecifier = JavaDateFormatSpecifierImpl.create("E");
} else {
if (numDays <= 28) {
displayGrouping = GroupingUnitType.WEEKS_LITERAL;
formatSpecifier = JavaDateFormatSpecifierImpl.create("MM/dd/yyyy");
} else {
displayGrouping = GroupingUnitType.MONTHS_LITERAL;
formatSpecifier = JavaDateFormatSpecifierImpl.create("MM/dd/yyyy");
}
}
SeriesGrouping grouping = sdX.getGrouping();
grouping.setGroupingUnit(displayGrouping);
grouping.setEnabled(true);
Terry