Dynamic data

Alejandro Flores <[email protected]> Fri, 16 Apr 2004 15:47:39 -0300
Newsgroups gmane.comp.krysalis.jcharts.user
Message-ID <1082141259.21746.8.camel@af>
	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



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click