setSeriesPaint not working correctly

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Ivoryn
Posts: 8
Joined: Tue Apr 04, 2006 2:01 pm

setSeriesPaint not working correctly

Post by Ivoryn » Thu Sep 28, 2006 2:31 pm

hi,

ich have a small problem with my chart. I have something like the MultipleAxisDemo, and setting the same color for the axis like the datasets is working fine.

now i implemented a button with which you can switch between a colored chart and a black&white chart. but when i want the chart to be displayed in black, only the axis and the first dataset get black, but the other lines (datasets) stay colored.

what did i do wrong?

here´s my sample code for what should happen when clicking on the button:

Code: Select all

case LINE_BTN:
        JButton lineButton = datasetView.getLineButton();

				JFreeChart chart = datasetView.chartPanel.getChart();
				int count = chart.getXYPlot().getDatasetCount();
				
				for (int i = 0; i < count; i++)
				{
					XYItemRenderer r = chart.getXYPlot().getRendererForDataset(chart.getXYPlot().getDataset(i));
					if (!linesColored)
					{
						lineButton.setIcon(Icons.lineBWIcon);
						lineButton.setToolTipText("Display black/white chart");
						
		                XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
		                renderer.setSeriesPaint(i, axisColor[i]);

		                chart.getXYPlot().getRangeAxisForDataset(i).setLabelPaint(axisColor[i]);
		                chart.getXYPlot().getRangeAxisForDataset(i).setTickLabelPaint(axisColor[i]);
		                chart.getXYPlot().setRenderer(i, renderer);						
					}
					else
					{
						lineButton.setIcon(Icons.lineColorIcon);
						lineButton.setToolTipText("Display colored chart");

		                XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
		                renderer.setSeriesPaint(i, axisColor[15]);

		                chart.getXYPlot().getRangeAxisForDataset(i).setLabelPaint(axisColor[15]);
		                chart.getXYPlot().getRangeAxisForDataset(i).setTickLabelPaint(axisColor[15]);
		                chart.getXYPlot().setRenderer(i, renderer);

					}
				}
				if (!linesColored) linesColored = true;			    
				else               linesColored = false;
			 }
			break;
i made my own Color[] axisColor which holds specific colors for my dataset. and axisColor[15] is the color black...

any ideas?

thanks in advance...

Ivoryn
Posts: 8
Joined: Tue Apr 04, 2006 2:01 pm

Post by Ivoryn » Thu Sep 28, 2006 2:44 pm

ok, i found the problem.

i should write:

Code: Select all

renderer.setSeriesPaint(i, axisColor[i]); 
instead, now i did:

Code: Select all

renderer.setSeriesPaint(0, axisColor[i]); 
still thanks for listening :lol:

Locked