我正试图让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 /组织/ jfree /图表/绘图/ 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 "";
    }
});

这项工作对我来说:

NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setTickLabelsVisible(false);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top