JFreeChart: Time Series Chart

I want to change the color and the thickness of the plot line in my chart.
If possible, please provide some sample code. Thanks!
Who is Participating?
for_yanConnect With a Mentor Commented:
See this section 36.2.4 in the book for color:

36.2.4 Setting Series Colours
Renderers are responsible for drawing the data items within a plot, so this class provides attributes
for controlling the colours that will be used. Colours are typically de ned on a \per series" basis,
and stored in a lookup table.
There is a default mechanism to automatically populate the lookup table with default colours (using
the DrawingSupplier interface). However, you can manually update the paint list at any time. First,
you need to obtain a reference to the renderer(s) (note that many charts do not use more than one
renderer). Here is the code for a CategoryPlot:
CategoryPlot plot = (CategoryPlot) chart.getPlot();
AbstractRenderer r1 = (AbstractRenderer) plot.getRenderer(0);
AbstractRenderer r2 = (AbstractRenderer) plot.getRenderer(1);
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 think here it shows how you can change stroke (setSeriesStroke method):

And the width is defined in BasicStroke

e.g. see example
on page 76 of the manual:

XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
renderer.setSeriesPaint(0, Color.red);
renderer.setSeriesPaint(1, Color.green);
renderer.setStroke(new BasicStroke(3f, BasicStroke.CAP_BUTT,
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.