如何在JFreeChart PieChart3D中填充渐变颜色?

发布于 2024-08-23 02:22:21 字数 1098 浏览 8 评论 0原文

我想用渐变颜色填充 PieChart3D,我使用 JFreeChart 来绘制图表。但它不是用渐变颜色填充,而是用纯色填充。这是我用于更改颜色的代码。

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

任何人都可以帮我解决这个问题吗?上面的代码适用于条形图,但不适用于饼图...我也尝试过 2D 但没有成功。

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..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不乱于心 2024-08-30 02:22:21

您的饼图是否仍在使用您的颜色,但不是渐变?我问的原因是,如果您看到默认颜色,那么您需要更改绘图的位置,这样它就不会自动填充部分颜色。我还没有在 3D 绘图上完成此操作,但我需要在 2D 绘图上这样做。

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.

终陌 2024-08-30 02:22:21

如果这是饼图的开始和结束范围相同的修复图表,那么您可以通过给出正确的 xy 坐标来实现这一点。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文