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

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

Introduction

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

Prototype

public void setNoDataMessage(String message) 

Source Link

Document

Sets the message that is displayed when the dataset is empty or null, and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:com.manydesigns.portofino.chart.Chart1DGenerator.java

public JFreeChart generate(ChartDefinition chartDefinition, Persistence persistence, Locale locale) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    java.util.List<Object[]> result;
    String query = chartDefinition.getQuery();
    logger.info(query);/*from  w  w  w  .  j av a2s  .  c o m*/
    Session session = persistence.getSession(chartDefinition.getDatabase());
    result = QueryUtils.runSql(session, query);
    for (Object[] current : result) {
        ComparableWrapper key = new ComparableWrapper((Comparable) current[0]);
        dataset.setValue(key, (Number) current[1]);
        if (current.length > 2) {
            key.setLabel(current[2].toString());
        }
    }

    JFreeChart chart = createChart(chartDefinition, dataset);

    chart.setAntiAlias(isAntiAlias());

    // impostiamo il bordo invisibile
    // eventualmente e' il css a fornirne uno
    // eventualmente e' il css a fornirne uno
    chart.setBorderVisible(isBorderVisible());

    // impostiamo il titolo
    TextTitle title = chart.getTitle();
    title.setFont(titleFont);
    title.setMargin(10.0, 0.0, 0.0, 0.0);

    // ottieni il Plot
    PiePlot plot = (PiePlot) chart.getPlot();

    String urlExpression = chartDefinition.getUrlExpression();
    if (!StringUtils.isBlank(urlExpression)) {
        PieURLGenerator urlGenerator = new ChartPieUrlGenerator(urlExpression);
        plot.setURLGenerator(urlGenerator);
    } else {
        plot.setURLGenerator(null);
    }

    // il plot ha sfondo e bordo trasparente
    // (quindi si vede il colore del chart)
    plot.setBackgroundPaint(transparentColor);
    plot.setOutlinePaint(transparentColor);

    // Modifico il toolTip
    // hongliangpan add
    // :?{0}  {1}  {2} ? ,???
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})",
            NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));
    // {0}={1}({2})
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}"));
    // ?(0.0-1.0)
    // plot.setForegroundAlpha(1.0f);
    // imposta la distanza delle etichette dal plot
    plot.setLabelGap(0.03);
    // plot.setLabelGenerator(new MyPieSectionLabelGenerator());

    // imposta il messaggio se non ci sono dati
    plot.setNoDataMessage(ElementsThreadLocals.getText("no.data.available"));

    plot.setCircular(true);

    plot.setBaseSectionOutlinePaint(Color.BLACK);

    DrawingSupplier supplier = new DesaturatedDrawingSupplier(plot.getDrawingSupplier());
    plot.setDrawingSupplier(supplier);
    // ?
    plot.setForegroundAlpha(1.0f);
    // impostiamo il titolo della legenda
    String legendString = chartDefinition.getLegend();
    Title subtitle = new TextTitle(legendString, legendFont, Color.BLACK, RectangleEdge.BOTTOM,
            HorizontalAlignment.CENTER, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0));
    subtitle.setMargin(0, 0, 5, 0);
    chart.addSubtitle(subtitle);

    // impostiamo la legenda
    LegendTitle legend = chart.getLegend();
    legend.setBorder(0, 0, 0, 0);
    legend.setItemFont(legendItemFont);
    int legendMargin = 10;
    legend.setMargin(0.0, legendMargin, legendMargin, legendMargin);
    legend.setBackgroundPaint(transparentColor);

    // impostiamo un gradiente orizzontale
    Paint chartBgPaint = new GradientPaint(0, 0, new Color(255, 253, 240), 0, getHeight(), Color.WHITE);
    chart.setBackgroundPaint(chartBgPaint);
    return chart;
}

From source file:org.pentaho.chart.plugin.jfreechart.JFreeChartFactoryEngine.java

public JFreeChart makePieChart(ChartModel chartModel, NamedValuesDataModel dataModel,
        final IChartLinkGenerator linkGenerator) {
    final DefaultPieDataset dataset = new DefaultPieDataset();
    for (NamedValue namedValue : dataModel) {
        if (namedValue.getName() != null) {
            dataset.setValue(namedValue.getName(),
                    scaleNumber(namedValue.getValue(), dataModel.getScalingFactor()));
        }/*from   w  w  w  . ja  v  a2 s  .  c o  m*/
    }

    boolean showLegend = (chartModel.getLegend() != null) && (chartModel.getLegend().getVisible());

    String title = "";
    if ((chartModel.getTitle() != null) && (chartModel.getTitle().getText() != null)
            && (chartModel.getTitle().getText().trim().length() > 0)) {
        title = chartModel.getTitle().getText();
    }

    final JFreeChart chart = ChartFactory.createPieChart(title, dataset, showLegend, true, false);

    initChart(chart, chartModel);

    final PiePlot jFreePiePlot = (PiePlot) chart.getPlot();

    if (linkGenerator != null) {
        jFreePiePlot.setURLGenerator(new PieURLGenerator() {

            public String generateURL(PieDataset arg0, Comparable arg1, int arg2) {
                return linkGenerator.generateLink(arg1.toString(), arg1.toString(), arg0.getValue(arg1));
            }
        });
    }

    jFreePiePlot.setNoDataMessage("No data available"); //$NON-NLS-1$
    jFreePiePlot.setCircular(true);
    jFreePiePlot.setLabelGap(0.02);

    org.pentaho.chart.model.PiePlot chartBeansPiePlot = (org.pentaho.chart.model.PiePlot) chartModel.getPlot();

    List<Integer> colors = getPlotColors(chartBeansPiePlot);

    int index = 0;
    for (NamedValue namedValue : dataModel) {
        if (namedValue.getName() != null) {
            jFreePiePlot.setSectionPaint(namedValue.getName(),
                    new Color(0x00FFFFFF & colors.get(index % colors.size())));
        }
        index++;
    }

    if (chartBeansPiePlot.getLabels().getVisible()) {
        jFreePiePlot.setLabelGenerator(new StandardPieSectionLabelGenerator());

        Font font = ChartUtils.getFont(chartBeansPiePlot.getLabels().getFontFamily(),
                chartBeansPiePlot.getLabels().getFontStyle(), chartBeansPiePlot.getLabels().getFontWeight(),
                chartBeansPiePlot.getLabels().getFontSize());
        if (font != null) {
            jFreePiePlot.setLabelFont(font);
            if (chartBeansPiePlot.getLabels().getColor() != null) {
                jFreePiePlot.setLabelPaint(new Color(0x00FFFFFF & chartBeansPiePlot.getLabels().getColor()));
            }
            if (chartBeansPiePlot.getLabels().getBackgroundColor() != null) {
                jFreePiePlot.setLabelBackgroundPaint(
                        new Color(0x00FFFFFF & chartBeansPiePlot.getLabels().getBackgroundColor()));
            }
        }
    } else {
        jFreePiePlot.setLabelGenerator(null);
    }

    jFreePiePlot.setStartAngle(-chartBeansPiePlot.getStartAngle());

    return chart;
}

From source file:fr.inria.soctrace.framesoc.ui.piechart.view.StatisticsPieChartView.java

/**
 * Creates the chart./*from   w w  w . j av  a  2s  .c  o m*/
 * 
 * @param dataset
 *            the dataset.
 * @param loader
 *            the pie chart loader
 * @param dataRequested
 *            flag indicating if the data have been requested for the current loader and the
 *            current interval
 * @return the pie chart
 */
private JFreeChart createChart(PieDataset dataset, String title, IPieChartLoader loader,
        boolean dataRequested) {

    JFreeChart chart = ChartFactory.createPieChart(title, dataset, HAS_LEGEND, HAS_TOOLTIPS, HAS_URLS);

    // legend
    if (HAS_LEGEND) {
        LegendTitle legend = chart.getLegend();
        legend.setPosition(RectangleEdge.LEFT);
    }

    // plot
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionOutlinesVisible(false);
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage(
            "No data available " + (dataRequested ? "in this time interval" : "yet. Press the Load button."));
    plot.setCircular(true);
    plot.setLabelGenerator(null); // hide labels
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlineVisible(false);
    plot.setShadowPaint(Color.WHITE);
    plot.setBaseSectionPaint(Color.WHITE);
    StandardPieToolTipGenerator g = (StandardPieToolTipGenerator) plot.getToolTipGenerator();
    NumberFormat format = ValueLabelProvider.getActualFormat(loader.getFormat(), getTimeUnit());
    StandardPieToolTipGenerator sg = new StandardPieToolTipGenerator(g.getLabelFormat(), format,
            g.getPercentFormat());
    plot.setToolTipGenerator(sg);

    for (Object o : dataset.getKeys()) {
        String key = (String) o;
        plot.setSectionPaint(key, loader.getColor(key).getAwtColor());
    }
    return chart;
}

From source file:cnu.eslab.fileTest.NewJFrame.java

public void PieGraphGenerate(String[] arGrop, double[] arValue, String arTitle, String arSubTitle) {
    // ??   ?.//from   w  w  w  .  jav  a2s .  c  o  m
    DefaultPieDataset data = new DefaultPieDataset();
    data.setValue(arGrop[0], arValue[0]); //CPU
    data.setValue(arGrop[1], arValue[1]); //WIFI
    data.setValue(arGrop[5], arValue[5]); //3G
    data.setValue(arGrop[2], arValue[2]); //LED
    data.setValue(arGrop[3], arValue[3]); //GPS
    data.setValue(arGrop[4], arValue[4]); //AUDIO

    //offset data .
    RectangleInsets pieOffset = new RectangleInsets(50.0, 50.0, 50.0, 50.0);

    //  ?  ?.
    JFreeChart chart = ChartFactory.createPieChart(arTitle, data, true, true, false);
    TextTitle subTitle = new TextTitle(arSubTitle);
    chart.setBackgroundPaint(Color.WHITE);
    chart.addSubtitle(subTitle);
    PiePlot pieplot = (PiePlot) chart.getPlot();
    pieplot.setNoDataMessage("No data available");
    pieplot.setExplodePercent("LED", 0.20000000000000001D);
    pieplot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1} mW) ({2} percent)"));
    pieplot.setLabelBackgroundPaint(new Color(220, 220, 220));
    pieplot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}"));
    //? 
    /*pieplot.setSectionPaint(arGrop[0], new Color(0,0,0));
    pieplot.setSectionPaint(arGrop[1], new Color(60,60,60));
    pieplot.setSectionPaint(arGrop[2], new Color(120,120,120));
    pieplot.setSectionPaint(arGrop[4], new Color(180,180,180));*/

    //pieplot.setSimpleLabels(true);
    //pieplot.setSimpleLabelOffset(pieOffset);   //?? offset? .

    pieplot.setInteriorGap(0.0D);

    // ??   ?.
    ChartPanel chartPanel = new ChartPanel(chart);
    JFrame f = new JFrame("");
    f.setSize(600, 600);
    f.getContentPane().add(chartPanel);

    // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:com.rapidminer.gui.plotter.charts.AbstractPieChartPlotter.java

public void updatePlotter() {
    int categoryCount = prepareData();
    String maxClassesProperty = ParameterService
            .getParameterValue(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_LEGEND_CLASSLIMIT);
    int maxClasses = 20;
    try {/*from   w  ww . ja  va 2  s.  c  o  m*/
        if (maxClassesProperty != null) {
            maxClasses = Integer.parseInt(maxClassesProperty);
        }
    } catch (NumberFormatException e) {
        // LogService.getGlobal().log("Pie Chart plotter: cannot parse property 'rapidminer.gui.plotter.colors.classlimit', using maximal 20 different classes.",
        // LogService.WARNING);
        LogService.getRoot().log(Level.WARNING,
                "com.rapidminer.gui.plotter.charts.AbstractPieChartPlotter.pie_chart_plotter_parsing_error");
    }
    boolean createLegend = categoryCount > 0 && categoryCount < maxClasses;

    if (categoryCount <= MAX_CATEGORIES) {
        JFreeChart chart = createChart(pieDataSet, createLegend);

        // set the background color for the chart...
        chart.setBackgroundPaint(Color.white);

        PiePlot plot = (PiePlot) chart.getPlot();

        plot.setBackgroundPaint(Color.WHITE);
        plot.setSectionOutlinesVisible(true);
        plot.setShadowPaint(new Color(104, 104, 104, 100));

        int size = pieDataSet.getKeys().size();
        for (int i = 0; i < size; i++) {
            Comparable<?> key = pieDataSet.getKey(i);
            plot.setSectionPaint(key, getColorProvider(true).getPointColor(i / (double) (size - 1)));

            boolean explode = false;
            for (String explosionGroup : explodingGroups) {
                if (key.toString().startsWith(explosionGroup) || explosionGroup.startsWith(key.toString())) {
                    explode = true;
                    break;
                }
            }

            if (explode) {
                plot.setExplodePercent(key, this.explodingAmount);
            }
        }

        plot.setLabelFont(LABEL_FONT);
        plot.setNoDataMessage("No data available");
        plot.setCircular(false);
        plot.setLabelGap(0.02);
        plot.setOutlinePaint(Color.WHITE);

        // legend settings
        LegendTitle legend = chart.getLegend();
        if (legend != null) {
            legend.setPosition(RectangleEdge.TOP);
            legend.setFrame(BlockBorder.NONE);
            legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
            legend.setItemFont(LABEL_FONT);
        }

        if (panel instanceof AbstractChartPanel) {
            panel.setChart(chart);
        } else {
            panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN);
            final ChartPanelShiftController controller = new ChartPanelShiftController(panel);
            panel.addMouseListener(controller);
            panel.addMouseMotionListener(controller);
        }

        // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
        panel.getChartRenderingInfo().setEntityCollection(null);
    } else {
        // LogService.getGlobal().logNote("Too many columns (" + categoryCount +
        // "), this chart is only able to plot up to " + MAX_CATEGORIES +
        // " different categories.");
        LogService.getRoot().log(Level.INFO,
                "com.rapidminer.gui.plotter.charts.AbstractPieChartPlotter.too_many_columns",
                new Object[] { categoryCount, MAX_CATEGORIES });
    }
}

From source file:org.hxzon.demo.jfreechart.PieDatasetDemo2.java

private static JFreeChart createPieChart(PieDataset dataset, PieDataset previousDataset) {
    final boolean greenForIncrease = true;
    final boolean subTitle = true;
    final boolean showDifference = true;
    int percentDiffForMaxScale = 20;
    PiePlot plot = new PiePlot(dataset);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator());
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));

    if (tooltips) {
        plot.setToolTipGenerator(new StandardPieToolTipGenerator());
    }//from  w ww . jav a  2 s .c  om
    if (urls) {
        plot.setURLGenerator(new StandardPieURLGenerator());
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    List<Comparable> keys = dataset.getKeys();
    DefaultPieDataset series = null;
    if (showDifference) {
        series = new DefaultPieDataset();
    }

    double colorPerPercent = 255.0 / percentDiffForMaxScale;
    for (@SuppressWarnings("rawtypes")
    Comparable key : keys) {
        Number newValue = dataset.getValue(key);
        Number oldValue = previousDataset.getValue(key);

        if (oldValue == null) {
            if (greenForIncrease) {
                plot.setSectionPaint(key, Color.green);
            } else {
                plot.setSectionPaint(key, Color.red);
            }
            if (showDifference) {
                series.setValue(key + " (+100%)", newValue);
            }
        } else {
            double percentChange = (newValue.doubleValue() / oldValue.doubleValue() - 1.0) * 100.0;
            double shade = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255
                    : Math.abs(percentChange) * colorPerPercent);
            if (greenForIncrease && newValue.doubleValue() > oldValue.doubleValue()
                    || !greenForIncrease && newValue.doubleValue() < oldValue.doubleValue()) {
                plot.setSectionPaint(key, new Color(0, (int) shade, 0));
            } else {
                plot.setSectionPaint(key, new Color((int) shade, 0, 0));
            }
            if (showDifference) {
                series.setValue(
                        key + " (" + (percentChange >= 0 ? "+" : "")
                                + NumberFormat.getPercentInstance().format(percentChange / 100.0) + ")",
                        newValue);
            }
        }
    }

    if (showDifference) {
        plot.setDataset(series);
    }

    JFreeChart chart = new JFreeChart("Pie Chart Demo 2", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    if (subTitle) {
        TextTitle subtitle = null;
        subtitle = new TextTitle("Bright " + (greenForIncrease ? "red" : "green") + "=change >=-"
                + percentDiffForMaxScale + "%, Bright " + (!greenForIncrease ? "red" : "green") + "=change >=+"
                + percentDiffForMaxScale + "%", new Font("SansSerif", Font.PLAIN, 10));
        chart.addSubtitle(subtitle);
    }
    plot.setNoDataMessage("No data available");

    return chart;

}

From source file:msi.gama.outputs.layers.ChartLayerStatement.java

private void createSlices(final IScope scope) throws GamaRuntimeException {
    int i = 0;//from   w ww.  j ava2s . co  m
    dataset = new DefaultPieDataset();
    final PiePlot plot = (PiePlot) chart.getPlot();
    for (final ChartData e : datas) {
        final String legend = e.getName();
        ((DefaultPieDataset) dataset).insertValue(i++, legend, null);
        history.append(legend);
        history.append(',');
    }
    if (history.length() > 0) {
        history.deleteCharAt(history.length() - 1);
    }
    history.append(Strings.LN);
    plot.setDataset((DefaultPieDataset) dataset);
    i = 0;
    for (final ChartData e : datas) {
        plot.setSectionPaint(i++, e.getColor());
    }
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1} ({2})"));
    if (exploded) {
        for (final Object c : ((DefaultPieDataset) dataset).getKeys()) {
            plot.setExplodePercent((Comparable) c, 0.20);
        }
    }
    plot.setSectionOutlinesVisible(false);
    plot.setLabelFont(getLabelFont());
    plot.setNoDataMessage("No data available yet");
    plot.setCircular(true);
    plot.setLabelGap(0.02);
    plot.setInteriorGap(0);
}