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.
Asked
Active
Viewed 218 times
1
-
What happens with `setSeriesPaint()`? – trashgod Feb 19 '18 at 10:18
-
Thanks, setSeriesPaint() giving only single color for all bubbles in a series, but I need custom color for each bubble in a series. – Robin Feb 20 '18 at 11:58
1 Answers
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