I am trying to get a horizontal gradient Fill for my Bars in the Barchart
that goes from color to white to color again in the same bar.
I tried the following:
Code: Select all
final BarRenderer renderer = new BarRenderer();
final CategoryPlot myPlot = new CategoryPlot();
myPlot.setRenderer(renderer);
myPlot.setDomainAxis(new CategoryAxis());
myPlot.setRangeAxis(new NumberAxis("y"));
myPlot.setOrientation(PlotOrientation.VERTICAL);
GradientPaint redGradient = new GradientPaint(
0.0f, 0.0f, Color.red,
0.0f, 0.0f, Color.white);
renderer.setGradientPaintTransformer(
new StandardGradientPaintTransformer(
GradientPaintTransformType.CENTER_HORIZONTAL));
renderer.setSeriesPaint(0, redGradient);
renderer.setSeriesPaint(1, java.awt.Color.lightGray );
renderer.setOutlinePaint(Color.black);
renderer.setOutlineStroke( new BasicStroke(0.7f) );
renderer.setMaximumBarWidth(0.10);
renderer.setItemMargin(0.05);
myPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
final JFreeChart chart = new JFreeChart(myPlot);
chart.setBackgroundPaint( Color.white );
chart.setBorderPaint( Color.black );
LegendTitle legend = chart.getLegend();
legend.setPosition( RectangleEdge.TOP );
legend.setBorder(BlockBorder.NONE);
CategoryAxis axis = (CategoryAxis) myPlot.getDomainAxis();
axis.setTickLabelFont(new java.awt.Font("SansSerif",java.awt.Font.PLAIN,8));
axis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
axis.setCategoryMargin(0.20f);
axis.setUpperMargin(0.02f);
axis.setLowerMargin(0.02f);
axis.setMaximumCategoryLabelLines(3);
axis.setMaximumCategoryLabelWidthRatio(15);
I'm sure it works this way but, I'm doing something wrong obviously!
Please help ?!
Thanks in advance!
Harris