【问题标题】:Hide labels on jfreechart/PiePlot3D piechart在 jfreechart/PiePlot3D 饼图上隐藏标签
【发布时间】:2009-11-26 14:54:35
【问题描述】:

我正在尝试让 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

【问题讨论】:

  • 你检查我的答案了吗?对此不予置评,也不接受。这对你不起作用吗?还是不是你想要的?

标签: java jfreechart


【解决方案1】:

这将隐藏所有标签:

plot.setLabelGenerator(null); //null means no labels

【讨论】:

    【解决方案2】:

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

    只需自己进行标签分配(匿名实现)并通过在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 "";
        }
    });
    

    【讨论】:

    • 所以?这符合您的要求吗?
    【解决方案3】:

    这对我有用:

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setTickLabelsVisible(false);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-05
      相关资源
      最近更新 更多