我想在我的 jfreechart PieChart3D 中更改饼图“ block ”的颜色,这是呈现饼图的代码:
<% response.setContentType("image/png"); %><%@page import="org.jfree.data.general.*"%><%@page import="org.jfree.chart.*"%><%@page import="org.jfree.chart.plot.*"%><%@page import="java.awt.Color" %><%
DefaultPieDataset ds = (DefaultPieDataset)session.getAttribute("usagePieOutputDataset");
JFreeChart chart = ChartFactory.createPieChart3D
(
null, // Title
ds, // Dataset
false, // Show legend
false, // Use tooltips
false // Configure chart to generate URLs?
);
chart.setBackgroundPaint(Color.WHITE);
chart.setBorderVisible(false);
PiePlot3D plot = ( PiePlot3D )chart.getPlot();
plot.setDepthFactor(0.0);
plot.setLabelGenerator(null); //null means no labels
plot.setLabelOutlinePaint(Color.LIGHT_GRAY);
plot.setLabelFont(new java.awt.Font("Arial", java.awt.Font.BOLD, 10));
ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 150, 144);
%>
非常感谢任何帮助。
最佳答案
每个部分的颜色通常由绘图的 DrawingSupplier 填充。不过,您可以通过调用
来覆盖默认值PiePlot.setSectionPaint(Comparable key, Paint paint);
不过,有了这个,您将需要手动设置每个部分。如果您只想要一组不同的颜色,看起来您可以实现 DrawingSupplier。
关于java - 改变jfreechart饼图的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1859313/