Jump to content
We've recently updated our Privacy Statement, available here ×

Grouping in Stacked Bar Chart


njrfrens

Recommended Posts

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

  • 3 weeks later...

Hello!

Can u tell me the setp-by-step process to acheive Grouping in stacked bar chart (using jFreeChart by "GroupedStackedBarRenderer"), if possible pls give some sample jrxml file.

 

Thanks & Regards,

Yash

 



Post Edited by yashdeep sant at 04/07/09 13:05
Link to comment
Share on other sites

below is the code to display GroupedStacked Bar chart using JFreeChart

Code:
public void generateStackedChart(OutputStream out, Object data) {	try {		JFreeChart chart = ChartFactory.createStackedBarChart(				"Alerts as % of Total Programs", "Alerts", "%",				getStackedDataSet(), 				PlotOrientation.VERTICAL, 				true, // include legend				false, // tooltips				false); // urls		GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();				KeyToGroupMap map = new KeyToGroupMap("G1");				map.mapKeyToGroup("Facility 1(ONE)", "G1");				map.mapKeyToGroup("Facility 2(ONE)", "G1");				map.mapKeyToGroup("Facility 3(ONE)", "G1");				map.mapKeyToGroup("Facility 4(ONE)", "G1");								map.mapKeyToGroup("Facility 1(ALL)", "G2");				map.mapKeyToGroup("Facility 2(ALL)", "G2");				map.mapKeyToGroup("Facility 3(ALL)", "G2");				map.mapKeyToGroup("Facility 4(ALL)", "G2");								renderer.setSeriesToGroupMap(map); 								CategoryPlot plot = (CategoryPlot) chart.getPlot();				plot.setRenderer(renderer);						BufferedImage buffImg = chart.createBufferedImage(500, // width				375, // height				BufferedImage.TYPE_INT_RGB, // image type				null);		ImageIO.write(buffImg, "jpeg", out);	} catch (IOException e) {		e.printStackTrace();	}}private DefaultCategoryDataset getStackedDataSet() {	DefaultCategoryDataset dataset = new DefaultCategoryDataset();	// dataset.addValue(1.0, "Row 1", "Column 1");	dataset.addValue(10.0, "Facility 1(ONE)", "Jan 2008");	dataset.addValue(50.0, "Facility 1(ONE)", "Feb 2008");	dataset.addValue(30.0, "Facility 1(ALL)", "Jan 2008");	dataset.addValue(25.0, "Facility 1(ALL)", "Feb 2008");		dataset.addValue(20.0, "Facility 2(ONE)", "Jan 2008");	dataset.addValue(30.0, "Facility 2(ONE)", "Feb 2008");	dataset.addValue(20.0, "Facility 2(ALL)", "Jan 2008");	dataset.addValue(30.0, "Facility 2(ALL)", "Feb 2008");		dataset.addValue(20.0, "Facility 3(ONE)", "Jan 2008");	dataset.addValue(30.0, "Facility 3(ONE)", "Feb 2008");	dataset.addValue(20.0, "Facility 3(ALL)", "Jan 2008");	dataset.addValue(30.0, "Facility 3(ALL)", "Feb 2008");		dataset.addValue(20.0, "Facility 4(ONE)", "Jan 2008");	dataset.addValue(30.0, "Facility 4(ONE)", "Feb 2008");	dataset.addValue(20.0, "Facility 4(ALL)", "Jan 2008");	dataset.addValue(20.0, "Facility 4(ALL)", "Feb 2008");	return dataset;}
Link to comment
Share on other sites

  • 4 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...