在jfreechart/PiePlot3D饼图上隐藏标签
问题描述:
我试图让jfreechart PieChart3D隐藏标签。我在文档中找不到任何东西。在jfreechart/PiePlot3D饼图上隐藏标签
任何人都知道如何做到这一点?
<% 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.setLabelOutlinePaint(Color.LIGHT_GRAY);
plot.setLabelFont(new java.awt.Font("Arial", java.awt.Font.BOLD, 10));
ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 150, 144);
%>
http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/PiePlot3D.html
答
这将隐藏所有标签:
plot.setLabelGenerator(null); //null means no labels
答
事实上,这似乎是一个更简单的方法,也更短。
只需自己做标签分发(匿名实现)并假装没有标签可以通过在getItemCount()
中返回一个零来显示。
plot.setLabelDistributor(new AbstractPieLabelDistributor() {
public int getItemCount() { return 0; }
public void distributeLabels(double minY,double height) {}
});
旧的解决方案:
不知道如果有一个更简单的方法,但这应该工作。应该是不言自明的。不要显示链接设置一些颜色透明,不生成标签。别的只是问。
Color transparent = new Color(0.0f,0.0f,0.0f,0.0f);
plot.setLabelLinksVisible(Boolean.FALSE);
plot.setLabelOutlinePaint(transparent);
plot.setLabelBackgroundPaint(transparent);
plot.setLabelShadowPaint(transparent);
plot.setLabelGenerator(new PieSectionLabelGenerator(){
@Override
public AttributedString generateAttributedSectionLabel(PieDataset dataset, Comparable key) {
return new AttributedString("");
}
@Override
public String generateSectionLabel(PieDataset dataset, Comparable key) {
return "";
}
});
+0
那么?这是否做你想要的? – jitter 2009-11-28 07:19:01
你检查我的答案?没有评论它,也没有被接受。这不适合你吗?或者不是你想要的? – jitter 2009-11-29 20:43:43