Question

J'essaie de faire en sorte que PieChart3D de jfreechart cache les étiquettes. Je ne trouve rien dans la documentation.

Quelqu'un sait comment faire cela?

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

Était-ce utile?

La solution

Ceci cachera toutes les étiquettes:

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

Autres conseils

En fait, cela semble être un moyen encore plus simple et beaucoup plus court.

Effectuez simplement la distribution d'étiquettes vous-même (implémentation anonyme) et prétendez qu'il n'y a aucune étiquette à afficher en renvoyant un zéro dans getItemCount () .

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

Ancienne solution:

Je ne sais pas s'il existe un moyen plus simple, mais cela devrait fonctionner. Devrait être explicite. Ne pas afficher les liens définissent certaines couleurs transparentes et ne génère pas d'étiquettes. Sinon, il suffit de demander.

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

Ce travail pour moi:

NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setTickLabelsVisible(false);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top