|
From: Alejandro F. <ale...@de...> - 2004-04-16 19:09:53
|
Hello There!
Sorry if this question have been answered, but I've searched the
archives and haven't found!
Well, I'm trying to create a dynamic bar chart, but can't figure out
how the labels/legends are connected to data.
I have an ArrayList with a component who have 2 properties: Name and
Val. The code I wrote was:
Color[] cores = new Color[] { Color.RED,
Color.BLUE,
Color.CYAN,
Color.DARK_GRAY,
Color.GRAY,
Color.GREEN,
Color.LIGHT_GRAY,
Color.MAGENTA,
Color.ORANGE,
Color.YELLOW };
int max = al.size();
String xAxisTitle= "Times";
String yAxisTitle= "Quantity";
String title= "Top 10";
String[] xAxisLabels = new String[max];
double[][] data = new double[max][1];
String[] legendLabels = new String[max];
Paint[] paints= new Paint[max]; //{ Color.blue.darker() };
for (int k = 0; k < max; k++) {
xAxisLabels[k] = ""+(k+1);
Account c = (Account) al.get(k);
data[k][0] = new Double(c.getVal()).doubleValue();
legendLabels[k] = c.getName();
paints[k] = colors[k];
}
DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle,
yAxisTitle, title );
BarChartProperties barChartProperties= new
BarChartProperties();
AxisChartDataSet axisChartDataSet= new AxisChartDataSet( data,
legendLabels, paints, ChartType.BAR, barChartProperties );
dataSeries.addIAxisPlotDataSet( axisChartDataSet );
ChartProperties chartProperties= new ChartProperties();
//---to make this plot horizontally, pass true to the
AxisProperties Constructor
//AxisProperties axisProperties= new AxisProperties( true );
AxisProperties axisProperties= new AxisProperties();
LegendProperties legendProperties= new LegendProperties();
legendProperties.setNumColumns(1);
AxisChart axisChart= new AxisChart(dataSeries, chartProperties,
axisProperties, legendProperties, 400, 300 );
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PNGEncoder.encode( axisChart, baos );
JLabel jl = new JLabel(new ImageIcon(baos.toByteArray()));
...
The exception is:
"The size of the Axis Labels Array does not match the number of data
elements to be plotted."
Thanks in advance!
Alejandro Flores
|