allelopath
asked on
JFreeChart: set color of plot lines
I am trying to set the color of lines on an XYPlot
2 problems:
1.
2. Calling setPaint() sets the color of every line in the plot. I want set specific lines to specific colors. How do I do that?
2 problems:
1.
lineShapeRenderer.setPaint()
is deprecated. What is supposed to be used?2. Calling setPaint() sets the color of every line in the plot. I want set specific lines to specific colors. How do I do that?
XYLineAndShapeRenderer lineShapeRenderer = new XYLineAndShapeRenderer();
lineShapeRenderer.setPaint(Color.black);
XYPlot combinedPlot = new XYPlot(collection, domainAxis, rangeAxis, renderer);
combinedPlot.setRenderer(lineShapeRenderer);
I am not sure what is AbstractRenderer r2,
but it look like r1 is sufficient.
This is the excerpt form manual, section 36.2.4,
you may try if it works
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That is how line coor are set up (from JFreeChart Manual):
The code is similar for charts that use XYPlot:
XYPlot plot = (XYPlot) chart.getPlot();
AbstractRenderer r1 = (AbstractRenderer) plot.getRenderer(0);
AbstractRenderer r2 = (AbstractRenderer) plot.getRenderer(1);
To update the series paint used by a renderer:
// change the paint for series 0, 1 and 2...
r1.setSeriesPaint(0, Color.red);
r1.setSeriesPaint(1, Color.green);
r1.setSeriesPaint(2, Color.blue);