Bar Chart Colors

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
chartprob

Bar Chart Colors

Post by chartprob » Fri Jun 24, 2005 3:04 pm

Hi,

I want to know how can I assign different colors to bars in a bar chart? The data belongs to only one series.

Thanks,

arik
Posts: 12
Joined: Mon Feb 21, 2005 7:20 pm

Post by arik » Sun Jun 26, 2005 5:10 pm

I think I saw a post about this issue, anyway the idea is to override the bar renderer's getItemPaint and setItemPaint using an array which contains the colors. I'm using it. It works like a charm.

Code: Select all

	private transient Paint paintArray[][];
	private boolean isPaintArray = false; 

	public Paint getItemPaint(int row, int column) {
		Paint returnPaint = null;
		
		if (isPaintArray) {
			returnPaint = paintArray[row][column];
		} else {
			returnPaint = super.getItemPaint(row, column);
		}
		return returnPaint; 
	} 


Locked