how can I change the color of my Piechart3D sections

Go To StackoverFlow.com

0

how can I change the color of every section in my PieChart3D,I tried like this:

private Color[] COLORS = {Color.red,Color.yellow,Color.blue,Color.black,Color.green};

private PieDataset createSampleDataset() {
        final DefaultPieDataset result = new DefaultPieDataset();
        result.setValue("Java", new Double(43.2));

        result.setValue("Visual Basic", new Double(10.0));
        result.setValue("C/C++", new Double(17.5));
        result.setValue("PHP", new Double(32.5));
        result.setValue("Perl", new Double(1.0));
        return result;
    }

    private JFreeChart createChart(PieDataset dataset) {
        final JFreeChart chart = ChartFactory.createPieChart3D(
            "Pie Chart 3D Demo 1",  // chart title
            dataset,                // data
            true,                   // include legend
            true,
            false
        );

        final PiePlot3D plot = (PiePlot3D) chart.getPlot();
        plot.setStartAngle(290);
        plot.setDirection(Rotation.CLOCKWISE);

        for(int i=0;i<COLORS.length;i++){
        plot.setSectionPaint(COLORS[i]);
        }

        plot.setForegroundAlpha(0.5f);
        plot.setNoDataMessage("No data to display");
        return chart;



    }

but every time when I compile,all the sections will have the green color,thanks for any help

2012-04-05 16:53
by hanem


1

Is this something along the lines of what you're look for?

Custom Colours for Pie Charts in JFreeChart

2012-04-05 17:00
by Devan Somaia
thanks Devan Somai - hanem 2012-04-05 18:41
Ads