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

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

Introduction

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

Prototype

public Font getLabelFont() 

Source Link

Document

Returns the section label font.

Usage

From source file:jmemorize.gui.swing.panels.SessionChartPanel.java

private JFreeChart createChart(String title, SessionSummary summary) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue(Localization.get(LC.LEARNED), (int) summary.getPassed());
    dataset.setValue(Localization.get(LC.FAILED), (int) summary.getFailed());
    dataset.setValue(Localization.get(LC.SKIPPED), (int) summary.getSkipped());
    dataset.setValue(Localization.get(LC.RELEARNED), (int) summary.getRelearned());

    JFreeChart chart = ChartFactory.createPieChart3D(title, dataset, true, true, false);

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setForegroundAlpha(0.5f);//from   ww  w .  ja  va2  s . co  m
    plot.setIgnoreZeroValues(true);

    plot.setLabelFont(plot.getLabelFont().deriveFont(11f));
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{1} ({2})"));

    plot.setSectionPaint(Localization.get(LC.LEARNED), ColorConstants.LEARNED_CARDS);
    plot.setSectionPaint(Localization.get(LC.FAILED), ColorConstants.EXPIRED_CARDS);
    plot.setSectionPaint(Localization.get(LC.SKIPPED), ColorConstants.UNLEARNED_CARDS);
    plot.setSectionPaint(Localization.get(LC.RELEARNED), ColorConstants.RELEARNED_CARDS);

    return chart;
}

From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreePieChartData.java

@Override
public JFreeChart getJFreeChart() {
    DefaultPieDataset pieDataset = makeDataSet();

    JFreeChart chart = ChartFactory.createPieChart(title, // Title
            pieDataset, // Dataset
            true // Show legend
            , false, false);/*ww w.  ja v a2  s  .c o m*/
    PiePlot plot = (PiePlot) chart.getPlot();

    StandardPieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0} ({2})");

    plot.setLabelGenerator(gen);
    plot.setMaximumLabelWidth(0.07);
    plot.setLabelFont(plot.getLabelFont().deriveFont(9.0F));

    LegendTitle leg = chart.getLegend();

    leg.setPosition(RectangleEdge.RIGHT);
    if (!colours.isEmpty()) {
        String legends[] = ds.getLegends();

        for (int i = 0; i < ds.getNumSets(); i++) {
            if (legends != null && legends.length > i && colours.size() > i) {
                Color c = colours.get(i);
                plot.setSectionPaint(legends[i], c);
            }
        }
    }

    return chart;

}

From source file:net.sourceforge.processdash.ui.web.reports.PieChart.java

/** Create a  line chart. */
@Override/*w  ww . ja  v a 2  s.  c  o m*/
public JFreeChart createChart() {
    CategoryDataset catData = data.catDataSource();
    PieDataset pieData = null;
    if (catData.getColumnCount() == 1)
        pieData = DatasetUtilities.createPieDatasetForColumn(catData, 0);
    else
        pieData = DatasetUtilities.createPieDatasetForRow(catData, 0);

    JFreeChart chart = null;
    if (get3DSetting()) {
        chart = ChartFactory.createPieChart3D(null, pieData, true, true, false);
        chart.getPlot().setForegroundAlpha(ALPHA);
    } else {
        chart = ChartFactory.createPieChart(null, pieData, true, true, false);
    }

    PiePlot plot = (PiePlot) chart.getPlot();
    if (parameters.get("skipItemLabels") != null || parameters.get("skipWedgeLabels") != null)
        plot.setLabelGenerator(null);
    else if (parameters.get("wedgeLabelFontSize") != null)
        try {
            float fontSize = Float.parseFloat((String) parameters.get("wedgeLabelFontSize"));
            plot.setLabelFont(plot.getLabelFont().deriveFont(fontSize));
        } catch (Exception lfe) {
        }
    if (parameters.get("ellipse") != null)
        plot.setCircular(true);
    else
        plot.setCircular(false);

    Object colorScheme = parameters.get("colorScheme");
    if ("byPhase".equals(colorScheme))
        maybeConfigurePhaseColors(plot, pieData);
    else if ("consistent".equals(colorScheme))
        // since 2.0.9
        configureConsistentColors(plot, pieData);
    else if (parameters.containsKey("c1"))
        configureIndividualColors(plot, pieData);

    String interiorGap = (String) parameters.get("interiorGap");
    if (interiorGap != null)
        try {
            plot.setInteriorGap(Integer.parseInt(interiorGap) / 100.0);
        } catch (NumberFormatException e) {
        }
    String interiorSpacing = (String) parameters.get("interiorSpacing");
    if (interiorSpacing != null)
        try {
            plot.setInteriorGap(Integer.parseInt(interiorSpacing) / 200.0);
        } catch (NumberFormatException e) {
        }

    if (!parameters.containsKey("showZeroValues")) {
        plot.setIgnoreZeroValues(true);
        plot.setIgnoreNullValues(true);
    }

    return chart;
}

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

@SuppressWarnings("unchecked")
@Override//from w  ww.j  a  va2  s .co  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;
}