开发者

How to Fill the gradient color in JFreeChart PieChart3D?

开发者 https://www.devze.com 2022-12-21 12:33 出处:网络
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 co

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);
        Gr开发者_高级运维adientPaint 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..


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.


If this is the fix chart having start and end range of your pie is same then you can achive that by giving correct x-y cordinates.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号