Link to home
Start Free TrialLog in
Avatar of allelopath
allelopath

asked on

JFreeChart: set color of plot lines

I am trying to set the color of lines on an XYPlot
2 problems:
1.
lineShapeRenderer.setPaint()

Open in new window

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

Open in new window

Avatar of for_yan
for_yan
Flag of United States of America image


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


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
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial