different colors for different parts of one chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
jgloving
Posts: 6
Joined: Wed Aug 13, 2008 9:36 pm

different colors for different parts of one chart

Post by jgloving » Mon Sep 15, 2008 3:35 pm

I'd like to use two colors to draw one chart. I want to divide it into two parts, each of them I'd like to use one color.
Is there someone who knows how to implement this effect? Thanks a lot!

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Post by matinh » Tue Sep 16, 2008 8:08 am

What kind of chart do you use? Barchart, linechart, other?
What exactly do you want to be in different colors? The actual data which the renderer draws or the plot's background, or anything else?

- martin

jgloving
Posts: 6
Joined: Wed Aug 13, 2008 9:36 pm

Post by jgloving » Tue Sep 16, 2008 2:57 pm

matinh wrote:What kind of chart do you use? Barchart, linechart, other?
What exactly do you want to be in different colors? The actual data which the renderer draws or the plot's background, or anything else?

- martin
It is linechart. I want to use one color to draw one half part of it, and use another color to draw the rest. What can I do? The color means the line's color. Thanks a lot

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Post by matinh » Tue Sep 16, 2008 3:09 pm

You have to modify the renderer class or provide your own using the setRenderer() method of your plot.

You probably use the XYLineAndShapeRenderer (which is the default for linecharts IIRC). So you have two possibilities:

* modify the source of XYLineAndShapeRenderer
* write your own renderer (eventually derive from XYLineAndShapeRenderer) and tell the plot to use it[/list]

I'd probably try the second suggestion. Have a look at the drawItem() method. You probably just want to override this method.

Also have a look at the getItemPaint() method from AbstractRenderer which is used by XYLineAndShapeRenderer. Eventually overriding this method is enough for your needs.

hth,
- martin

skunk
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Post by skunk » Tue Sep 16, 2008 4:15 pm

This question is asked over and over. Search is your friend

http://www.jfree.org/phpBB2/viewtopic.php?t=16931

Locked