java 在 jfreechart/PiePlot3D 饼图上隐藏标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1804145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 18:03:14  来源:igfitidea点击:

Hide labels on jfreechart/PiePlot3D piechart

javajfreechart

提问by timkl

I'm trying to get the jfreechart PieChart3D to hide labels. I can't find anything in the documentation.

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

Anyone know how to do this?

有人知道怎么做吗?

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

http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/PiePlot3D.html

回答by Adam

This will hide all labels:

这将隐藏所有标签:

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

回答by jitter

Actually this seems to be an even easier way and also much shorter.

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

Just do the label distribution yourself (anonymous implementation) and pretend that there are no labels to display by returning a zero in getItemCount().

只需自己进行标签分发(匿名实现),并通过在getItemCount().

plot.setLabelDistributor(new AbstractPieLabelDistributor() {
    public int getItemCount() { return 0; }
    public void distributeLabels(double minY,double height) {}
});


Old solution:

旧解决方案:

Don't know if there is an easier way but this should work. Should be self-explanatory. Don't show links set some colors transparent and don't generate labels. Else just ask.

不知道是否有更简单的方法,但这应该可行。应该是不言自明的。不显示链接将一些颜色设置为透明并且不生成标签。别的就问吧。

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 "";
    }
});

回答by J. L. Pacheco

This work for me:

这对我有用:

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