Robin
Robin

Reputation: 563

Bubble chart with custom colors in each bubble in a series

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.

Upvotes: 1

Views: 260

Answers (1)

trashgod
trashgod

Reputation: 205785

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);

Upvotes: 1

Related Questions