?
Solved

JFreeChart: Time Series Chart

Posted on 2011-09-27
3
Medium Priority
?
488 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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month15 days, 12 hours left to enroll

850 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