1

我试图让 jfreechart PieChart3D 隐藏标签。我在文档中找不到任何内容。

有人知道怎么做吗?

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

4

3 回答 3

14

这将隐藏所有标签:

plot.setLabelGenerator(null); //null means no labels
于 2009-11-30T17:52:02.700 回答
1

实际上,这似乎是一种更简单的方法,也更短。

只需自己进行标签分发(匿名实现)并通过在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 "";
    }
});
于 2009-11-26T18:00:33.173 回答
0

这对我有用:

NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setTickLabelsVisible(false);
于 2018-04-14T18:53:40.400 回答