views:

354

answers:

1

I want to fill the PieChart3D with a gradient color, I am using JFreeChart for drawing the graph. but it is not filling with gradient color rather than it is filled with a solid color.. Here is the code I am using for changing the color.

public void setColor(PiePlot3D plot, PieDataset dataset) {
        GradientPaint gp0 = new GradientPaint(1.0f, 1.0f, Color.BLACK,
                0.3f, 2.1f, Color.lightGray);
        GradientPaint gp1 = new GradientPaint(0.5f, 0.5f, Color.green,
                0.0f, 0.0f, Color.lightGray);
        GradientPaint gp2 = new GradientPaint(0.5f, 0.5f, Color.red,
                0.0f, 0.0f, Color.lightGray);

        List<Comparable> keys = dataset.getKeys();
        int aInt;

        for (int i = 0; i < keys.size(); i++) {
            aInt = i % this.color.length;
            if (i == 0) {
                plot.setSectionPaint(keys.get(i), gp0);
                plot.setBackgroundPaint(gp0);
            }
            if (i == 1) {
                plot.setSectionPaint(keys.get(i), gp1);
            }
            if (i == 2) {
                plot.setSectionPaint(keys.get(i), gp2);
            }
        }
    }

any onle can please help me out on this? the above code is working for bar chart but not in piechart... I ahve also tried 2D with out any success..

A: 

Is your pie chart still using your colors, but not in a gradient? The reason I ask is that if you are seeing the default colors then you need to change where your plot so it doesn't auto-populate the section colors. I haven't done this on a 3D plot, but I needed to for a 2D plot.

Adam
Yes it is filling (not the default) the color but Gradient color is not there, only solid color. e.g. "GradientPaint gp0" gives only Solid Black color, rathar than gradient from balck to gray.
Ummar
Not sure then. I would post on the jfree forum: http://www.jfree.org/phpBB2 The maker of jfreechart is very helpful as is the community. Be sure to cross reference so if you get an answer in one place others can find it in the other.
Adam