1

I am new to JFreeChart. I am trying to create a bubble chart that has a single series with up to 10 bubble, but I want to different color for each bubble. I tried xyitemrenderer.setSeriesFillPaint(0, Color.GREEN). But it giving only one color for all bubbles. How to setup multiple color for each bubbles in JFreeChart.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Robin
  • 533
  • 2
  • 5
  • 16

1 Answers1

1

I need custom color for each bubble in a series.

As shown here, you can override the renderer's getItemPaint() implementation to return any desired color. The following example prints the default colors totes console.

JFreeChart chart = …;
XYPlot xyplot = (XYPlot) chart.getPlot();
XYItemRenderer xyitemrenderer = new XYBubbleRenderer(){
    @Override
    public Paint getItemPaint(int row, int col) {
        Paint p = super.getItemPaint(row, col);
        System.out.println(row + ", " + col + ": " + p);
        return p;
    }
};
xyplot.setRenderer(xyitemrenderer);
trashgod
  • 203,806
  • 29
  • 246
  • 1,045