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)
Bar and line combo chart for same column as a group?
Arif shah
<p>Hi,</p><p> </p><p>I have attached a very simple data that I would like to show in a combo of Bar and line chart. I have a Town Column which has My Town against other towns.</p><p> </p><p>I want to compare My town with other towns by making My Town as a Bar chart and the other towns as a line chart going through the bar chart as shown the attached image of the chart</p><p> </p><p>I have created the attached chart by creating a different column for each town and then creating a different series for each town. However, I would like to do it based on the format of table that I have shown above. I want to do it in a single series rather than creating separate series for each town because we don't know how many towns will be there in the data so we want to do it dynamically. Can someone please help</p><p> </p><p>Regards</p><p>Arif</p>
Find more posts tagged with
Comments
mwilliams
If you create a line chart and have the crime type as the x-axis value, the crime count as the y-axis value, and the town field as the optional grouping value, you don't need to create a series for each town. With this method, you'll need to use some script to turn the "My Town" series into a bar series. That can be done with something like the script below:<br><pre class="_prettyXprint _lang-js _linenums:0">importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
importPackage(Packages.org.eclipse.birt.chart.model.type.impl);
function beforeGeneration( chart, icsc ){
yAxis = chart.getAxes()[0].getAssociatedAxes()[0];
seriesDef = yAxis.getSeriesDefinitions()[0];
for(i=0;i<seriesDef.getSeries().size();i++){
if(seriesDef.getSeries()[i].getSeriesIdentifier() == "My Town"){
ds = seriesDef.getSeries()[i].getDataSet();
}
}
ns = BarSeriesImpl.create();
ns.setDataSet(ds);
ns.setSeriesIdentifier("My Town");
seriesDef.getSeries().add(ns);
seriesDef.getSeries().move(0,ns);
}</pre>This script finds the "My Town" series, copies the dataSet, creates a new bar series, adds it to the chart, then moves it to the front of the series list so it doesn't cover up the line series lines.<br> <br>Hope this helps.
Arif shah
<p>Hi William,</p>
<p> </p>
<p>This is an excellent solution. Can you please tell me how to change the bar type to "2D with Depth" through the script?</p>
<p> </p>
<p>Arif</p>
mwilliams
Try adding this to your script.<br><br>At the top with the other imports:<br><br>importPackage(Packages.org.eclipse.birt.chart.model.attribute);<br><br>In the beforeGeneration function:<br><br>chart.setDimension(ChartDimension.TWO_DIMENSIONAL_WITH_DEPTH_LITERAL);