Pregunta

Estoy intentando que el PieChart3D de jfreechart oculte las etiquetas. No puedo encontrar nada en la documentación.

¿Alguien sabe cómo hacer esto?

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

¿Fue útil?

Solución

Esto ocultará todas las etiquetas:

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

Otros consejos

En realidad, esto parece ser una forma aún más fácil y también mucho más corta.

Solo haga la distribución de etiquetas (implementación anónima) y pretenda que no hay etiquetas para mostrar devolviendo un cero en getItemCount () .

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

Solución anterior:

No sé si hay una manera más fácil, pero esto debería funcionar. Debe ser autoexplicativo. No mostrar enlaces establece algunos colores transparentes y no generar etiquetas. De lo contrario, solo pregunte.

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

Este trabajo para mí:

NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setTickLabelsVisible(false);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top