我已经使用JFreeChart创建了XY线图,有两个数据集,我希望两行都是不同的颜色.我尝试使用以下代码 –
XYPlot plot = chart.getXYPlot(); XYItemRenderer xyir = plot.getRenderer(); xyir.setSeriesPaint(0,Color.GREEN); plot.setDataset(0,xyDataset1); xyir.setSeriesPaint(1,Color.blue); plot.setDataset(1,xyDataset2);
我也尝试使用以下代码,我使用不同的渲染器(不知道这是否是正确的方法)
XYPlot plot1 = chart.getXYPlot(); XYPlot plot2 = chart.getXYPlot(); XYItemRenderer xyir1 = plot1.getRenderer(); xyir1.setSeriesPaint(0,Color.GREEN); plot1.setDataset(0,xyDataset1); XYItemRenderer xyir2 = plot2.getRenderer(); xyir2.setSeriesPaint(1,Color.blue); plot2.setDataset(1,xyDataset2);
在这两种情况下,它们都以蓝色印刷线条.
怎么了??有什么建议么??
解决方法@H_403_13@
找到解决方案,它适用于我,使用两个不同的渲染器,早期我没有做好 –
XYPlot plot = chart.getXYPlot();
plot.setDataset(0,xyDataset1);
plot.setDataset(1,xyDataset2);
XYLineAndShapeRenderer renderer0 = new XYLineAndShapeRenderer();
XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer();
plot.setRenderer(0,renderer0);
plot.setRenderer(1,renderer1);
plot.getRendererForDataset(plot.getDataset(0)).setSeriesPaint(0,Color.red);
plot.getRendererForDataset(plot.getDataset(1)).setSeriesPaint(0,Color.blue);
XYPlot plot = chart.getXYPlot(); plot.setDataset(0,xyDataset1); plot.setDataset(1,xyDataset2); XYLineAndShapeRenderer renderer0 = new XYLineAndShapeRenderer(); XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(); plot.setRenderer(0,renderer0); plot.setRenderer(1,renderer1); plot.getRendererForDataset(plot.getDataset(0)).setSeriesPaint(0,Color.red); plot.getRendererForDataset(plot.getDataset(1)).setSeriesPaint(0,Color.blue);