Bar chart

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

Bar chart

Post by Spip » Wed Jun 08, 2005 8:50 am

Hello,

I am trying to create a bar chart. I have to put several colors, one for the first bars, and other colors for next bars, etc.
To do that, I put as many series as there are colors, but the problem is that the bars are not aligned with the scale on the horizontal axe.
I am wondering if it is possible to set several successive colors for one serie.
Has anybody something to propose to solve it ?

Thanks a lot in anticipation.

dimdim
Posts: 9
Joined: Mon Jun 06, 2005 8:23 am

Post by dimdim » Wed Jun 08, 2005 12:02 pm

I think not, but I am interested.

Dim

Rahul Gupta
Posts: 11
Joined: Wed Apr 20, 2005 1:55 pm
Location: India

Post by Rahul Gupta » Wed Jun 08, 2005 1:37 pm

I think u can it, just try some method in renderer to set colors.
Rahul K. Gupta

Spip

Post by Spip » Fri Jun 10, 2005 11:38 am

I just extended BarRenderer class.

In calculateBarWidth and calculateBarW0 methods, I replaced dataset.getRowCount() by one.

Then, you have just to set one serie by bar, and one color by serie.

It is not very powerful, but it works.

padhu
Posts: 7
Joined: Tue Jun 07, 2005 8:31 pm

Post by padhu » Mon Jun 13, 2005 3:58 pm

Extend BarRenderer and override drawItem. Set color for each item before calling super.drawItem.


-- pady

cris-rj
Posts: 16
Joined: Mon Oct 11, 2004 2:44 pm
Location: rio de janeiro, brazil

Post by cris-rj » Wed Jun 15, 2005 1:48 pm

here is my code for it:

Code: Select all


class BarCategoryRenderer extends BarRenderer { 


	Paint paintArray[][]; 

	  public Paint getItemPaint(int column, int row) { 
		return paintArray[row][column]; 
	  } 

	  public void setItemPaint(Paint paint, int row, int column) { 
		paintArray[row][column]=paint; 
	  } 

	  public void setPaintListSize(int rowCount, int columnCount,Paint defaultPaint) { 
		paintArray = new Paint[rowCount][columnCount]; 
		for(int row=0; row<rowCount; row++) { 
		  for(int col=0; col<columnCount; col++) { 
			paintArray[row][col]=defaultPaint; 
		  } 
		} 
	  } 

	  public void setSeriesPaints(int QCol,int QLin,Cores cor) { 
		paintArray = new Paint[QLin][QCol]; 
		Paint paint1[];	
		for(int row=0; row<QLin; row++) { 
		  for(int col=0; col<QCol; col++) { 
			paint1 = new Paint[]{ cor.PegaCor(cor.CoresAUsar[QCol][col+1]) };
			paintArray[row][col]=paint1[0]; 
		  } 
		} 
	  } 
}


public class Cores {

  	    public Cores(int n){
			EsquemaCor = n;	
      	}
      	public int EsquemaCor;

		public int cores[][] = {
		 {},//Para acertar o esq.1 com o índice 1 e assim por diante.
		 /*Esquma 1*/
		 {0,0xFFFF00,0xF05C38,0xB07870,0xD02C30,0x50E8F0,0x30A020,0xB068A8,0x808080,0xB09C10,0x00CCB0,0x4044B0,0x98EC40,0xB040C0,0x18A4F8,0xA85400,0x5870D0,0xD1F2FA,0xE7F5E8,0xFCF7D8},//1     
		 /*Esquma 2*/
		 {0,0xFFD0FF,0xFFFFD0,0xFFE4D8,0xC8FFC8,0xC8E4FF,0xD8D8D8,0xC8C8FF,0xC0FFFF,0xFFA8A8,0xD8D8B0,0x98B088,0xB8C070,0x90A8B8,0xFFFF80,0x808080,0xFFA478,0xD1F2FA,0xE7F5E8,0xFCF7D8},//2
		 /*Esquma 3*/
		 {0,0xFFFF00,0xFFD000,0xFFA400,0xFF7800,0xFF4800,0xFF4C10,0xE83810,0xD02418,0xB81430,0xA00038,0xA00040,0x801450,0x682868,0x484080,0x305498,0x285498,0xD1F2FA,0xE7F5E8,0xFCF7D8},//3
		 /*Esquma 4*/
		 {0,0xE8D810,0xE8BC18,0xE09C20,0xE08030,0xD86038,0xD84040,0xB05040,0x805840,0x586840,0x287040,0x008040,0x007448,0x006860,0x005C68,0x004C70,0x004080,0xEEE2D0,0xDCE8DB,0xCEECE3},
		 /*Esquma 5*/
		 {0,0xFFFF00,0xFFEC00,0xFFDC00,0xFFC800,0xFFB800,0xFFA400,0xFF9400,0xFF8000,0xF07000,0xE06000,0xD05000,0xC04000,0xB03000,0xA02000,0x981000,0x800000,0xFFFFDF,0xFBF5E6,0xF9ECEC},//5
		 /*Esquma 6*/
		 {0,0xFFFF80,0xFFEC80,0xFFD880,0xFFC880,0xFFB480,0xFFA480,0xFF9480,0xFF8080,0xF08088,0xE08090,0xD08098,0xC080A0,0xB080A8,0xA080B0,0x9080B8,0x8080C0,0xFFFFDF,0xF9F9F2,0xE1E1F0},
		 /*Esquma 7*/
		 {0,0xF0D468,0xD8CC78,0xB8C488,0x98BC90,0x80B8A0,0x60B0B0,0x48ACC0,0x30A8D8,0x4094B8,0x5884A8,0x687490,0x806478,0x905460,0xB04850,0xC03840,0xD82828,0xD2E9FF,0xF0F2F1,0xF7E8D2},//7
		 /*Esquma 8*/
		 {0,0xF0E0A8,0xE0D8B0,0xC8C8B0,0xB0BCB0,0xA0B0B8,0x88A4C0,0x7098B8,0x608CC0,0x6878B0,0x7868A8,0x8858A0,0x984890,0xA03488,0xA82078,0xC01070,0xC80068,0xFEFED6,0xF9F1E2,0xF4E3EE},
		 /*Esquma 9*/
		 {0,0xB8D4F0,0xC0D4D8,0xC8D4C0,0xD0D4B0,0xD8D498,0xD8D498,0xD0C090,0xD0B088,0xD0A088,0xD09080,0xC88C80,0xC07478,0xB85C80,0xB04078,0xA02470,0xA02070,0xECF4ED,0xF6FAE9,0xFFFFE6},//9
		 /*Esquma 10*/
		 {0,0xFFFF80,0xD8FC88,0xB0F888,0x90F490,0x70F098,0x48F098,0x58D8B0,0x60C0C0,0x68ACD8,0x68ACD8,0x8080FF,0x9864E8,0xB04CC8,0xC830B0,0xE01898,0xFF0080,0xF5EED6,0xF9EDDD,0xFCECE4},
		 /*Esquma 11*/
		 {0,0xD8F4B0,0xD8E8B0,0xE0E0B0,0xE0D8B0,0xE8D0B8,0xF0C8B8,0xD8B8B8,0xC0ACB8,0xA89CB8,0x9894C0,0x8884C0,0x7080A8,0x607888,0x507468,0x406C48,0x306830,0xECF4ED,0xF6FAE9,0xFFFFE6},//11
		 /*Esquma 12*/
		 {0,0xFFFF80,0xE0F890,0xC0F098,0xA0ECA8,0x80E8B0,0x60E0B8,0x40DCC8,0x28D8D8,0x20C4C8,0x20B0B0,0x18A0A0,0x108C88,0x107878,0x106868,0x105458,0x004040,0xE1F4DD,0xF0F9E4,0xFEFCE9},
		 /*Esquma 13*/
		 {0,0xF8FF78,0xE0E870,0xD8D070,0xD0B868,0xC0A060,0xB8A060,0xB09058,0xA08458,0x987858,0x806848,0x886853,0x606C68,0x486C80,0x207098,0x0070A8,0x0070BC,0xCDE6F1,0xE5F0E5,0xFEFADA},//13
		 /*Esquma 14*/
		 {0,0xF0F0F0,0xF0E4D0,0xF0D8B0,0xF0D090,0xE8C470,0xE0BC68,0xD0B460,0xC0A860,0xB0A060,0xA09058,0xA09060,0x888068,0x707070,0x586480,0x405488,0x405490,0xE1F4EC,0xDFEDEE,0xDDE7F0},
		 /*Esquma 15*/
		 {0,0xF0FF78,0xE8E878,0xD8D070,0xD0B868,0xC0A060,0xB09058,0xA08458,0x987850,0x907450,0x886850,0x886848,0x706848,0x606840,0x486440,0x306430,0x306438,0xE7D3C2,0xDEDFCB,0xD5EBD3},//15
		 /*Esquma 16*/
		 {0,0xFFFFFF,0xF0ECF0,0xE0DCE0,0xC8C8C8,0xB8B8B8,0xA8A4A8,0x909090,0x808080,0x787878,0x707070,0x686468,0x605C60,0x505450,0x484848,0x403C40,0x383438,0xFFFFFF,0xECECEC,0xDADADA},
		};

		public Color PegaCor(int Ncor){
			Color cor1 = new Color(cores[EsquemaCor][Ncor]);
		  return cor1;	
		}	
	
	public int CoresAUsar[][]=
	{{},//Para acertar os índices. 1 Coluna -> índice 1.
	 {0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	 {0,2,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	 {0,2,8,15,0,0,0,0,0,0,0,0,0,0,0,0,0},
	 {0,2,6,10,15,0,0,0,0,0,0,0,0,0,0,0,0},
	 {0,2,6,9,12,16,0,0,0,0,0,0,0,0,0,0,0},
	 {0,2,5,7,10,13,15,0,0,0,0,0,0,0,0,0,0},
	 {0,2,4,6,8,11,13,15,0,0,0,0,0,0,0,0,0},
	 {0,2,4,6,8,10,12,14,16,0,0,0,0,0,0,0,0},
	 {0,1,3,5,6,8,10,11,13,15,0,0,0,0,0,0,0},
	 {0,1,3,4,6,8,9,11,12,14,16,0,0,0,0,0,0},
	 {0,1,2,4,5,7,8,9,11,12,14,15,0,0,0,0,0},
	 {0,1,2,3,5,6,7,9,10,11,13,14,15,0,0,0,0},
	 {0,1,2,3,4,6,7,8,9,10,12,13,14,15,0,0,0},
	 {0,1,2,3,4,5,6,7,8,9,11,12,13,14,15,0,0},
	 {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0},
	 {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}};

}

[]´s
Cristiano

Locked