Re: [Fwd: Dynamic data]

"Nathaniel G. Auvil" <[email protected]> Fri, 16 Apr 2004 12:42:56 -0700 (PDT)
Newsgroups gmane.comp.krysalis.jcharts.user
Message-ID <[email protected]>
you have 'max' as the number of labels, but your dataset only contains a single item for 'max'
datasets.  I think what you want is to have double[1][max] as your data and String[1] for your
legend labels.



--- Alejandro Flores <[email protected]> wrote:
> 	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
> _______________________________________________
> jCharts-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jcharts-users



	
		
__________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
http://taxes.yahoo.com/filing.html


-------------------------------------------------------
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