如何在JFreeChart PieChart3D中填充渐变颜色?
我想用渐变颜色填充 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的饼图是否仍在使用您的颜色,但不是渐变?我问的原因是,如果您看到默认颜色,那么您需要更改绘图的位置,这样它就不会自动填充部分颜色。我还没有在 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.
如果这是饼图的开始和结束范围相同的修复图表,那么您可以通过给出正确的 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.