• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1635
  • Last Modified:

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

0
allelopath
Asked:
allelopath
  • 2
1 Solution
 
for_yanCommented:

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

0
 
for_yanCommented:

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
0
 
objectsCommented:
XYLineAndShapeRenderer lineShapeRenderer = new XYLineAndShapeRenderer();
lineShapeRenderer.setSeriesPaint(0, Color.black);
lineShapeRenderer.setSeriesPaint(1, Color.red);
lineShapeRenderer.setSeriesPaint(2, Color.blue);

example here:
http://www.jfree.org/phpBB2/viewtopic.php?p=69285&highlight=&sid=be6e63e84f27d0217e28dac2b3ebe180
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now