Example usage for org.jfree.chart.plot PiePlot setLabelLinksVisible

List of usage examples for org.jfree.chart.plot PiePlot setLabelLinksVisible

Introduction

In this page you can find the example usage for org.jfree.chart.plot PiePlot setLabelLinksVisible.

Prototype

public void setLabelLinksVisible(boolean visible) 

Source Link

Document

Sets the flag that controls whether or not label linking lines are visible and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:Visuals.PieChart.java

public ChartPanel drawPieChart() {
    DefaultPieDataset piedataset = new DefaultPieDataset();
    if (riskCount == 0) {
        title = "";
        piedataset.setValue(noVulnerabilities, new Integer(1));
    } else {//from   w  ww.  j a v  a  2  s  .com
        piedataset.setValue(lowValue, new Integer(low));
        piedataset.setValue(mediumValue, new Integer(medium));
        piedataset.setValue(highValue, new Integer(high));
        piedataset.setValue(criticalValue, new Integer(critical));
    }

    JFreeChart piechart = ChartFactory.createPieChart(title, // Title  
            piedataset, // Dataset  
            true, // Show legend  
            true, // Use tooltips  
            false // Generate URLs  
    );

    PiePlot plot = (PiePlot) piechart.getPlot();
    //plot.setSimpleLabels(true); 
    if (riskCount == 0) {
        plot.setSectionPaint(noVulnerabilities, new Color(47, 196, 6));
        plot.setLabelLinksVisible(false);
        plot.setLabelGenerator(null);
        piechart.removeLegend();
    } else {
        plot.setSectionPaint(criticalValue, new Color(230, 27, 27));
        plot.setSectionPaint(highValue, new Color(230, 90, 27));
        plot.setSectionPaint(mediumValue, new Color(85, 144, 176));
        plot.setSectionPaint(lowValue, new Color(230, 219, 27));
    }

    if (isMain) {
        piechart.removeLegend();
    }
    plot.setBackgroundPaint(new Color(210, 234, 243));
    ChartPanel chartPanel = new ChartPanel(piechart);
    chartPanel.setEnabled(false);
    return chartPanel;
}

From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputPie.java

@Override
public void initChart(final IScope scope, final String chartname) {
    super.initChart(scope, chartname);

    final PiePlot pp = (PiePlot) chart.getPlot();
    pp.setShadowXOffset(0);// w  w  w.  j av  a 2  s.  c o m
    pp.setShadowYOffset(0);
    if (!this.series_label_position.equals("none")) {
        pp.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1} ({2})"));
        if (axesColor != null) {
            pp.setLabelLinkPaint(axesColor);
        }
        pp.setLabelFont(getTickFont());
    }
    if (this.series_label_position.equals("none")) {
        pp.setLabelLinksVisible(false);
        pp.setLabelGenerator(null);

    }
    if (textColor != null) {
        // pp.setLabelPaint(textColor);
        // not for Pie since the label background is always yellow for
        // now...
    }

}

From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java

/**
 * Creates a Pie Chart based on map./* w w w  .  j ava2s . c  o  m*/
 *
 * @return the Pie Chart generated.
 */
public JFreeChart getPieChart(Map<String, Double> pieValues) {
    DefaultPieDataset dataset = new DefaultPieDataset();

    for (String key : pieValues.keySet()) {
        dataset.setValue(key, pieValues.get(key));
    }

    JFreeChart chart = ChartFactory.createPieChart3D(null, // chart title
            dataset, // data
            true, // include legend
            true, false);

    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(false);
    chart.setBorderPaint(null);

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionOutlinesVisible(false);
    plot.setLabelFont(new Font("SansSerif", Font.BOLD, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(true);
    plot.setLabelGap(0.02);
    plot.setOutlinePaint(null);
    plot.setLabelLinksVisible(false);

    plot.setLabelGenerator(null);

    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}"));

    plot.setStartAngle(270);
    plot.setDirection(Rotation.ANTICLOCKWISE);
    plot.setForegroundAlpha(0.60f);
    plot.setInteriorGap(0.33);

    return chart;
}

From source file:edu.jhuapl.graphs.jfreechart.JFreeChartPieGraphSource.java

@SuppressWarnings("unchecked")
@Override//w w  w . ja v a2s . c  o m
public void initialize() throws GraphException {
    String title = getParam(GraphSource.GRAPH_TITLE, String.class, DEFAULT_TITLE);
    boolean legend = getParam(GraphSource.GRAPH_LEGEND, Boolean.class, DEFAULT_GRAPH_LEGEND);
    boolean graphToolTip = getParam(GraphSource.GRAPH_TOOL_TIP, Boolean.class, DEFAULT_GRAPH_TOOL_TIP);
    boolean graphDisplayLabel = getParam(GraphSource.GRAPH_DISPLAY_LABEL, Boolean.class, false);
    boolean legendBorder = getParam(GraphSource.LEGEND_BORDER, Boolean.class, DEFAULT_LEGEND_BORDER);
    boolean graphBorder = getParam(GraphSource.GRAPH_BORDER, Boolean.class, DEFAULT_GRAPH_BORDER);
    Font titleFont = getParam(GraphSource.GRAPH_FONT, Font.class, DEFAULT_GRAPH_TITLE_FONT);
    String noDataMessage = getParam(GraphSource.GRAPH_NO_DATA_MESSAGE, String.class,
            DEFAULT_GRAPH_NO_DATA_MESSAGE);
    PieGraphData pieGraphData = makeDataSet();
    Map<Comparable, Paint> colors = pieGraphData.colors;

    this.chart = ChartFactory.createPieChart(title, pieGraphData.data, false, graphToolTip, false);

    Paint backgroundColor = getParam(GraphSource.BACKGROUND_COLOR, Paint.class, DEFAULT_BACKGROUND_COLOR);
    Paint plotColor = getParam(JFreeChartTimeSeriesGraphSource.PLOT_COLOR, Paint.class, backgroundColor);
    Paint labelColor = getParam(JFreeChartTimeSeriesGraphSource.GRAPH_LABEL_BACKGROUND_COLOR, Paint.class,
            DEFAULT_BACKGROUND_COLOR);

    this.chart.setBackgroundPaint(backgroundColor);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(plotColor);
    plot.setNoDataMessage(noDataMessage);

    if (!graphDisplayLabel) {
        plot.setLabelGenerator(null);
    } else {
        plot.setInteriorGap(0.001);
        plot.setMaximumLabelWidth(.3);
        //           plot.setIgnoreNullValues(true);
        plot.setIgnoreZeroValues(true);
        plot.setShadowPaint(null);
        //           plot.setOutlineVisible(false);
        //TODO use title font?
        Font font = plot.getLabelFont();
        plot.setLabelLinkStyle(PieLabelLinkStyle.CUBIC_CURVE);
        plot.setLabelFont(font.deriveFont(font.getSize2D() * .75f));
        plot.setLabelBackgroundPaint(labelColor);
        plot.setLabelShadowPaint(null);
        plot.setLabelOutlinePaint(null);
        plot.setLabelGap(0.001);
        plot.setLabelLinkMargin(0.0);
        plot.setLabelLinksVisible(true);
        //           plot.setSimpleLabels(true);
        //           plot.setCircular(true);
    }

    if (!graphBorder) {
        plot.setOutlineVisible(false);
    }

    if (title != null && !"".equals(title)) {
        TextTitle title1 = new TextTitle();
        title1.setText(title);
        title1.setFont(titleFont);
        title1.setPadding(3, 2, 5, 2);
        chart.setTitle(title1);
    } else {
        chart.setTitle((TextTitle) null);
    }
    plot.setLabelPadding(new RectangleInsets(1, 1, 1, 1));
    //Makes a wrapper for the legend to remove the border around it
    if (legend) {
        LegendTitle legend1 = new LegendTitle(chart.getPlot());
        BlockContainer wrapper = new BlockContainer(new BorderArrangement());

        if (legendBorder) {
            wrapper.setFrame(new BlockBorder(1, 1, 1, 1));
        } else {
            wrapper.setFrame(new BlockBorder(0, 0, 0, 0));
        }

        BlockContainer items = legend1.getItemContainer();
        items.setPadding(2, 10, 5, 2);
        wrapper.add(items);
        legend1.setWrapper(wrapper);
        legend1.setPosition(RectangleEdge.BOTTOM);
        legend1.setHorizontalAlignment(HorizontalAlignment.CENTER);

        if (params.get(GraphSource.LEGEND_FONT) instanceof Font) {
            legend1.setItemFont(((Font) params.get(GraphSource.LEGEND_FONT)));
        }

        chart.addSubtitle(legend1);
        plot.setLegendLabelGenerator(new PieGraphLabelGenerator());
    }

    for (Comparable category : colors.keySet()) {
        plot.setSectionPaint(category, colors.get(category));
    }

    plot.setToolTipGenerator(new PieGraphToolTipGenerator(pieGraphData));
    plot.setURLGenerator(new PieGraphURLGenerator(pieGraphData));

    initialized = true;
}