Need help with stacked area chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
PortlandDeveloper
Posts: 4
Joined: Fri Aug 11, 2006 11:08 pm

Need help with stacked area chart

Post by PortlandDeveloper » Tue Dec 19, 2006 7:23 pm

Here is what I'm trying to achieve: I have a 3D bar chart of a performance measure score. In the background I need to show categories (good, excellent, poor) so that user can look at the bar chart and see which category each bar is in. To get the background I am using stacked area charts.

I am using a multi-dimensional array to set values for each line(section) in the stacked area chart. For the size of the array, I use the same number as I have bars in the bar chart. (i.e. if 2 bars, I use array [5][2]. For some reason that creates a very narrow area chart. I need my area chart to fill the whole background of chart.

Here is my code for stacked area charts :
//create Dataset for categories
int smallSize = small_chart_data.getColumnCount() + 2;
double[][] data = new double[5][smallSize] ;
int i=0;
for (i=0; i<smallSize; i++)
data[0] = 0.49;
for (i=0; i<smallSize; i++)
data[1] = 0.20;
for (i=0; i<smallSize; i++)
data[2]=0.15;
for (i=0; i<smallSize; i++)
data[3]=0.09;
for (i=0; i<smallSize; i++)
data[4]=0.07;
CategoryDataset categoryLine = DatasetUtilities.createCategoryDataset("","",data);

//create and customize a renderer for categories
StackedAreaRenderer renderer2 = new StackedAreaRenderer();
renderer2.setSeriesPaint(0, Color.gray);
renderer2.setSeriesPaint(1, Color.red);
renderer2.setSeriesPaint(2, Color.yellow);
renderer2.setSeriesPaint(3, Color.green);
renderer2.setSeriesPaint(4, Color.blue);

//add dataset and renderer to chart
small_chart.getCategoryPlot().setDataset(1,categoryLine);
small_chart.getCategoryPlot().setRenderer(1,renderer2);
small_chart.getCategoryPlot().setForegroundAlpha(1.0f);
small_chart.getCategoryPlot().setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);

//add customized legend to plots
LegendItemCollection items = new LegendItemCollection();
items.add(new LegendItem("Unacceptable", "Unacceptable", "Unacceptable", "", new java.awt.geom.Rectangle2D.Float(0, 0, 10, 10),Color.gray));
items.add(new LegendItem("Poor", "Poor", "Poor", "", new java.awt.geom.Rectangle2D.Float(0, 0, 10, 10), Color.red));
items.add(new LegendItem("Fair", "Fair", "Fair", "", new java.awt.geom.Rectangle2D.Float(0, 0, 10, 10), Color.yellow));
items.add(new LegendItem("Good", "Good", "Good", "", new java.awt.geom.Rectangle2D.Float(0, 0, 10, 10), Color.green));
items.add(new LegendItem("Excellent", "Excellent", "Excellent", "", new java.awt.geom.Rectangle2D.Float(0, 0, 10, 10), Color.blue));
small_chart.getCategoryPlot().setFixedLegendItems(items);


Please help! :?
Thank you

Locked