Custom Colors in Bar Chart : JfreeChart
February 13, 2007 – 12:24 amSample Bar chart with custom colors
Following is the Beanshell code to produce the above custom colors.
CustomBarRenderer barRenderer = new CustomBarRenderer(
new Paint[]
{
new Color(193,157,246),
new Color(152,185,185),
new Color(72,72,117),
new Color(157,141,110),
new Color(181,181,119),
new Color(151,199,151),
new Color(191,167,182),
new Color(217,182,144),
new Color(102,153,255),
new Color(0,102,102),
new Color(84,72,84),
new Color(180,236,203),
}
);
plot.setRenderer(barRenderer);
barRenderer.setDrawBarOutline(false);
/*
barRenderer.setOutlinePaint(Color.blue);
barRenderer.setOutlineStroke(new BasicStroke(1.1f, BasicStroke.JOIN_ROUND, BasicStroke.JOIN_BEVEL));
GradientPaint gp0 = new GradientPaint( 0.0f, 0.0f, Color.blue, 0.0f, 0.0f,Color.white );
GradientPaint gp1 = new GradientPaint( 0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray );
GradientPaint gp2 = new GradientPaint( 0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray );
barRenderer.setSeriesPaint(0, gp0);
barRenderer.setSeriesPaint(1, gp1);
barRenderer.setSeriesPaint(2, gp2);
barRenderer.setGradientPaintTransformer( new StandardGradientPaintTransformer( GradientPaintTransformType.HORIZONTAL));
*/
float h = displayFrame.getHeight();
float w = displayFrame.getWidth();
// GradientPaint gradientPaint = new GradientPaint(0.0F, 10.0F, Color.WHITE, h, w, Color.green.darker());
//plot.setBackgroundPaint(gradientPaint);
chart.setBackgroundPaint(new GradientPaint(0,0, Color.gray,0,h, new Color(55,35,13)));
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setTickLabelPaint(Color.white);
domainAxis.setTickLabelFont(new Font(”Arial”,Font.BOLD,12));
domainAxis.setLabelPaint(Color.white);
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setTickLabelPaint(Color.WHITE);
rangeAxis.setTickLabelFont(new Font(”Arial”,Font.BOLD,12));
rangeAxis.setLabelPaint(Color.white);
chart.getTitle().setPaint(Color.white);
//chart.getTitle().setText(”Top 5 Tables by Row Count”);
