how do i customize bars colors in Bar chart..

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
sreehari.ojili
Posts: 14
Joined: Tue May 06, 2008 5:57 am

how do i customize bars colors in Bar chart..

Post by sreehari.ojili » Thu May 08, 2008 6:38 am

hi every body, i create bar chart, created chart bars are displayed with default colors, how do i customize bars colors in Bar chart..

Thanks in advance

keyboarder
Posts: 9
Joined: Thu Apr 17, 2008 2:23 pm

Post by keyboarder » Thu May 08, 2008 1:43 pm

hi sreehari.ojili

You need to override the method getItemPaint in the BarRenderer class...

Example:

Code: Select all

plot.setRenderer(new BarRenderer(){
     public Paint getItemPaint(int row, int item) {
          if (item == 0) return Color.RED;
     }
}); 
I hope that help you...


hug,
Keyboarder

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

Post by skunk » Thu May 08, 2008 2:20 pm

The default sequence of colors etc is defined by org.jfree.chart.plot.DefaultDrawingSupplier

To change the sequence, create a new instance of DrawingSupplier and then call this method

Code: Select all

public void setDrawingSupplier(DrawingSupplier supplier)
on your plot.

If you only need to customize colors for a particular chart, then just call

Code: Select all

renderer.setSeriesPaint(int series, java.awt.Paint paint)

sreehari.ojili
Posts: 14
Joined: Tue May 06, 2008 5:57 am

Post by sreehari.ojili » Thu May 08, 2008 4:36 pm

hi, thanks to all,

here my case is to customise only particular chart , the below code fixed my problem..

Code: Select all

renderer.setSeriesPaint(int series, java.awt.Paint paint)
i have one more query i am using dual axis chart (combination of bar & line chart). i am using ploting line chart by using below code.

i want to increase the line size(i mean line width)

Code: Select all

 final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(true, false);
	     renderer2.setSeriesPaint(0, new Color(153, 153, 255));

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

Post by skunk » Thu May 08, 2008 7:41 pm

Code: Select all

renderer2.setSeriesStroke(int series, java.awt.Stroke stroke)

sreehari.ojili
Posts: 14
Joined: Tue May 06, 2008 5:57 am

Post by sreehari.ojili » Fri May 09, 2008 10:46 am

hi skunk :) thanks a lot,
the code which u posted is fixed my problem..

i am facing one more problem i need to put one small line between each categories.. and i need to print category labels in in two lines alternatively...

i have only one series in my domain axis..i am print 30 items(dates) in domain axis. first item label(01/03) has to print in first line and second item label(02/03) has to print in another line..please help me to come out of this problem.

it needs to be print as mentioned below order

___|___|___|___|___|___|___|___|___|___|___|___|___| domain axis
01/03 03/03 05/03 07/03 09/03
02/03 04/03 06/03 07/03







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

Post by skunk » Fri May 09, 2008 1:28 pm

Not supported. You will need to write some code.

sreehari.ojili
Posts: 14
Joined: Tue May 06, 2008 5:57 am

Post by sreehari.ojili » Fri May 09, 2008 1:34 pm

hi skunk, thanks for your reply, can send/post ur mail id, so that i will send my template image and what outout i got using jfree.. image will give me detail view...


Thanks in Advance,
Sreehari Ojili..
sreehari.ojili@cambridge-asia.com

sreehari.ojili
Posts: 14
Joined: Tue May 06, 2008 5:57 am

Post by sreehari.ojili » Fri May 09, 2008 1:36 pm

hi skunk, sorry for type mistakes, can send/post ur mail id, so that i will send my template image and what outout i got using jfree.. image will give you detail view...


Thanks in Advance,
Sreehari Ojili..
sreehari.ojili@cambridge-asia.com

Locked