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

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

Introduction

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

Prototype

public void setIgnoreZeroValues(boolean flag) 

Source Link

Document

Sets a flag that controls whether zero values are ignored, and sends a PlotChangeEvent to all registered listeners.

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   w  ww  . j a v a 2  s.com
    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:com.googlecode.logVisualizer.chart.PieChartBuilder.java

private JFreeChart createChart(final PieDataset dataset) {

    final JFreeChart chart = ChartFactory.createPieChart(getTitle(), dataset, isIncludeLegend(), true, false);
    final PiePlot plot = (PiePlot) chart.getPlot();

    plot.setSectionOutlinesVisible(false);
    plot.setNoDataMessage("No data available");
    plot.setIgnoreNullValues(true);/*from  w  w  w .  j  a v a 2  s . c  o  m*/
    plot.setIgnoreZeroValues(true);

    return chart;
}

From source file:edu.gmu.cs.sim.util.media.chart.PieChartGenerator.java

protected void buildChart() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    chart = ChartFactory.createMultiplePieChart("Untitled Chart", dataset, org.jfree.util.TableOrder.BY_COLUMN,
            false, true, false);/*from w w  w .jav  a2 s.c  o m*/
    chart.setAntiAlias(true);
    //chartPanel = new ScrollableChartPanel(chart, true);            
    chartPanel = buildChartPanel(chart);
    //chartHolder.getViewport().setView(chartPanel);
    setChartPanel(chartPanel);

    JFreeChart baseChart = (JFreeChart) ((MultiplePiePlot) (chart.getPlot())).getPieChart();
    PiePlot base = (PiePlot) (baseChart.getPlot());
    base.setIgnoreZeroValues(true);
    base.setLabelOutlinePaint(java.awt.Color.WHITE);
    base.setLabelShadowPaint(java.awt.Color.WHITE);
    base.setMaximumLabelWidth(0.25); // allow bigger labels by a bit (this will make the chart smaller)
    base.setInteriorGap(0.000); // allow stretch to compensate for the bigger label width
    base.setLabelBackgroundPaint(java.awt.Color.WHITE);
    base.setOutlinePaint(null);
    base.setBackgroundPaint(null);
    base.setShadowPaint(null);
    base.setSimpleLabels(false); // I think they're false anyway

    // change the look of the series title to be smaller
    StandardChartTheme theme = new StandardChartTheme("Hi");
    TextTitle title = new TextTitle("Whatever", theme.getLargeFont());
    title.setPaint(theme.getAxisLabelPaint());
    title.setPosition(RectangleEdge.BOTTOM);
    baseChart.setTitle(title);

    // this must come last because the chart must exist for us to set its dataset
    setSeriesDataset(dataset);
}

From source file:org.sonar.server.charts.deprecated.PieChart.java

private void configurePlot() {
    PiePlot plot = (PiePlot) jfreechart.getPlot();
    plot.setNoDataMessage(DEFAULT_MESSAGE_NODATA);
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setDataset(dataset);//from ww  w  .  j ava 2  s  . c  o m
    plot.setBackgroundAlpha(0.0f);
    plot.setCircular(true);
    plot.setLabelGenerator(null);
    plot.setIgnoreNullValues(true);
    plot.setIgnoreZeroValues(true);
    plot.setShadowPaint(null);
    plot.setLabelLinkMargin(0.0);
    plot.setInteriorGap(0.02);
    plot.setMaximumLabelWidth(0.10);
}

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

@SuppressWarnings("unchecked")
@Override/* w w w .  ja  va 2s.c  om*/
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;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.PieChartExpression.java

protected void configureChart(final JFreeChart chart) {
    super.configureChart(chart);

    final Plot plot = chart.getPlot();
    final PiePlot pp = (PiePlot) plot;
    final PieDataset pieDS = pp.getDataset();
    pp.setDirection(rotationClockwise ? Rotation.CLOCKWISE : Rotation.ANTICLOCKWISE);
    if ((explodeSegment != null) && (explodePct != null)) {
        configureExplode(pp);//w  w  w.  ja  v a2  s .c om
    }
    if (StringUtils.isEmpty(getTooltipFormula()) == false) {
        pp.setToolTipGenerator(new FormulaPieTooltipGenerator(getRuntime(), getTooltipFormula()));
    }
    if (StringUtils.isEmpty(getUrlFormula()) == false) {
        pp.setURLGenerator(new FormulaPieURLGenerator(getRuntime(), getUrlFormula()));
    }

    pp.setIgnoreNullValues(ignoreNulls);
    pp.setIgnoreZeroValues(ignoreZeros);
    if (Boolean.FALSE.equals(getItemsLabelVisible())) {
        pp.setLabelGenerator(null);
    } else {
        final ExpressionRuntime runtime = getRuntime();
        final Locale locale = runtime.getResourceBundleFactory().getLocale();

        final FastDecimalFormat fastPercent = new FastDecimalFormat(FastDecimalFormat.TYPE_PERCENT, locale);
        final FastDecimalFormat fastInteger = new FastDecimalFormat(FastDecimalFormat.TYPE_INTEGER, locale);

        final DecimalFormat numFormat = new DecimalFormat(fastInteger.getPattern(),
                new DecimalFormatSymbols(locale));
        numFormat.setRoundingMode(RoundingMode.HALF_UP);

        final DecimalFormat percentFormat = new DecimalFormat(fastPercent.getPattern(),
                new DecimalFormatSymbols(locale));
        percentFormat.setRoundingMode(RoundingMode.HALF_UP);

        final StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator(pieLabelFormat,
                numFormat, percentFormat);
        pp.setLabelGenerator(labelGen);

        final StandardPieSectionLabelGenerator legendGen = new StandardPieSectionLabelGenerator(
                pieLegendLabelFormat, numFormat, percentFormat);
        pp.setLegendLabelGenerator(legendGen);
    }

    if (StringUtils.isEmpty(getLabelFont()) == false) {
        pp.setLabelFont(Font.decode(getLabelFont()));
    }

    if (pieDS != null) {
        final String[] colors = getSeriesColor();
        for (int i = 0; i < colors.length; i++) {
            if (i < pieDS.getItemCount()) {
                pp.setSectionPaint(pieDS.getKey(i), parseColorFromString(colors[i]));
            } else {
                break;
            }
        }
    }

    if (shadowPaint != null) {
        pp.setShadowPaint(shadowPaint);
    }
    if (shadowXOffset != null) {
        pp.setShadowXOffset(shadowXOffset.doubleValue());
    }
    if (shadowYOffset != null) {
        pp.setShadowYOffset(shadowYOffset.doubleValue());
    }
    pp.setCircular(circular);

    if (isShowBorder() == false || isChartSectionOutline() == false) {
        chart.setBorderVisible(false);
        chart.getPlot().setOutlineVisible(false);
    }

}

From source file:de.dekarlab.moneybuilder.view.AnalyticsView.java

/**
 * Create pie chart./* w  w  w.ja  v  a  2 s . c  om*/
 * 
 * @param dataset
 * @param title
 * @return
 */
protected JFreeChart createPieChart(final PieDataset dataset, final String title) {
    final JFreeChart chart = ChartFactory.createPieChart(title, dataset, true, true, false);
    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setNoDataMessage(App.getGuiProp("report.nodata.msg"));
    plot.setCircular(true);
    // plot.set
    plot.setLabelGap(0.02);
    plot.setBackgroundPaint(Color.white);
    chart.removeLegend();
    plot.setBackgroundPaint(Color.white);
    Iterator<?> it = dataset.getKeys().iterator();
    int color = 0;
    while (it.hasNext()) {
        plot.setSectionPaint((String) it.next(), COLORS[color]);
        color++;
        if (COLORS.length == color) {
            color = 0;
        }
    }
    plot.setLabelBackgroundPaint(Color.white);
    StandardPieSectionLabelGenerator slbl = new StandardPieSectionLabelGenerator("{0} {2} ({1})",
            new DecimalFormat("#,##0"), new DecimalFormat("0%"));
    plot.setLabelGenerator(slbl);
    plot.setLabelFont(new Font("Helvetica", Font.PLAIN, 14));
    plot.setLabelOutlinePaint(Color.white);
    plot.setLabelShadowPaint(Color.white);
    plot.setShadowPaint(Color.white);
    plot.setIgnoreZeroValues(true);
    return chart;
}

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

/** Create a  line chart. */
@Override/*from w ww . j  a  va2s.  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;
}