Solved

JFreeChart: Time Series Chart

Posted on 2011-09-27
3
444 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
  • 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 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
array11 challenge 16 52
where is session ID cache stored 1 40
topping1 challenge 7 53
wordappend challenge 8 85
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now