?
Solved

JFreeChart: Time Series Chart

Posted on 2011-09-27
3
Medium Priority
?
465 Views
Last Modified: 2012-05-12
I want to change the color and the thickness of the plot line in my chart.
If possible, please provide some sample code. Thanks!
0
Comment
Question by:dshrenik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36712763


I think here it shows how you can change stroke (setSeriesStroke method):
http://www.java2s.com/Code/Java/Chart/JFreeChartLineChartDemo5showingtheuseofacustomdrawingsupplier.htm
0
 
LVL 47

Accepted Solution

by:
for_yan earned 2000 total points
ID: 36712840
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);
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36712873


And the width is defined in BasicStroke
http://download.oracle.com/javase/1.4.2/docs/api/java/awt/BasicStroke.html#BasicStroke%28float%29

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,
BasicStroke.JOIN_BEVEL));
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question