We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

JFreeChart: set color of plot lines

allelopath
allelopath asked
on
Medium Priority
3,063 Views
Last Modified: 2012-05-11
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

Comment
Watch Question

Awarded 2011
Awarded 2011

Commented:

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

Awarded 2011
Awarded 2011

Commented:

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
Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.