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:cn.edu.thss.iise.bpmdemo.statistics.actions.ModelReusePanel.java

private JPanel createPanel() throws IOException {
    createDataSet();// w  w w.j a va2 s .c  o  m

    // create the chart...
    final JFreeChart chart = ChartFactory.createPieChart("Reused Times", // chart
            // title
            data1, // dataset
            false, // include legend
            true, false);

    // set the background color for the chart...
    chart.setBackgroundPaint(new Color(222, 222, 255));

    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setCircular(true);
    plot.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data available");

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

    String[] columnNames = { "Name", "Reuse Times" };
    JTable table = new JTable(data2, columnNames);
    JPanel panel = new JPanel();
    panel.add(chartPanel);
    panel.add(table);
    final Rotator rotator = new Rotator(plot);
    rotator.start();
    return panel;
}

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

/**
 * Create pie chart./*from   w w w. ja  v  a 2s  .  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:it.eng.spagobi.engines.chart.bo.charttypes.piecharts.SimplePie.java

public JFreeChart createChart(DatasetMap datasets) {

    Dataset dataset = (Dataset) datasets.getDatasets().get("1");

    JFreeChart chart = null;/*from  ww  w.j ava  2 s  . c  om*/

    if (!threeD) {
        chart = ChartFactory.createPieChart(name, (PieDataset) dataset, // data
                legend, // include legend
                true, false);

        chart.setBackgroundPaint(color);

        TextTitle title = chart.getTitle();
        title.setToolTipText("A title tooltip!");

        PiePlot plot = (PiePlot) chart.getPlot();
        plot.setLabelFont(new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize()));
        plot.setCircular(false);
        plot.setLabelGap(0.02);
        plot.setNoDataMessage("No data available");

        if (percentage == false) {
            plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1})"));
        } else {
            plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})"));
        }

    } else {
        chart = ChartFactory.createPieChart3D(name, (PieDataset) dataset, // data
                true, // include legend
                true, false);

        chart.setBackgroundPaint(color);

        TextTitle title = chart.getTitle();
        title.setToolTipText("A title tooltip!");

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

        plot.setDarkerSides(true);
        plot.setStartAngle(290);
        plot.setDirection(Rotation.CLOCKWISE);
        plot.setForegroundAlpha(1.0f);
        plot.setDepthFactor(0.2);

        plot.setLabelFont(new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize()));
        // plot.setNoDataMessages("No data available");
        plot.setCircular(false);
        plot.setLabelGap(0.02);
        plot.setNoDataMessage("No data available");

        if (percentage == false) {
            plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1})"));
        } else {
            plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})"));
        }
    }

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    return chart;

}

From source file:edu.ucla.stat.SOCR.chart.demo.PieChartDemo1.java

/**
 * Creates a chart/*from ww  w  .  j a v a 2s.  c  om*/
 * 
 * @param dataset  the dataset.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(PieDataset dataset) {
    JFreeChart chart = ChartFactory.createPieChart(chartTitle, // chart title
            dataset, // data
            !legendPanelOn, // include legend
            true, false);
    TextTitle title = chart.getTitle();
    title.setToolTipText("A title tooltip!");

    PiePlot plot = (PiePlot) chart.getPlot();
    for (int i = 0; i < pulloutFlag.length; i++) {
        //System.out.println("\""+pulloutFlag[i]+"\"");
        if (isPullout(i)) {
            Comparable key = dataset.getKey(i);
            plot.setExplodePercent(key, 0.30);
        }
    }
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);

    setCategorySummary(dataset);

    if (rotateOn) {
        Rotator rotator = new Rotator(plot);
        rotator.start();
    }
    return chart;
}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.PieChartRenderer.java

public void createChart() {

    PieDataset dataset = (PieDataset) this.datasetStrategy.getDataset();
    report = ChartFactory.createPieChart(this.datasetStrategy.getTitle(), dataset, true, true, false);
    PiePlot plot = (PiePlot) report.getPlot();
    //        plot.setCircular( false );
    plot.setDirection(Rotation.ANTICLOCKWISE);
    /*/*from   w ww.  j  a v  a2  s .c  o  m*/
     * plot.setExplodePercent(0, 0.15D); plot.setExplodePercent(1, 0.15D);
     */
    //        plot.setInteriorGap( PieChartRenderer.INTERIOR_GAP );
    plot.setLabelFont(new Font("Lucida", 0, PieChartRenderer.FONT_SIZE));
    plot.setLabelGap(PieChartRenderer.LABEL_GAP);
    plot.setNoDataMessage("No data available");
    plot.setStartAngle(PieChartRenderer.START_ANGLE);
    Paint[] paints = this.datasetStrategy.getPaintColor();

    for (int i = 0; i < dataset.getItemCount() && i < paints.length; i++) {
        plot.setSectionPaint(dataset.getKey(i), paints[i]);
    }
}

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

/**
 * Create a simple pie chart without title, legend, label etc.
 * /*from ww  w.  j  a va2  s .  c om*/
 * @param dataset
 *            the dataset to be renderer
 * @param colors
 *            an color array specify each item's color. The order of the
 *            array correspond to the item order in dataset
 * @return a pie chart
 */
public static JFreeChart createPlainPieChart(PieDataset dataset, Color[] colors) {
    if (dataset == null) {
        throw new IllegalArgumentException("No dataset.");
    }
    if (colors != null && colors.length != dataset.getItemCount()) {
        throw new IllegalArgumentException("Data have " + dataset.getItemCount() + " values, while we have "
                + colors.length + " colors for them.");
    }

    JFreeChart jfreechart = ChartFactory.createPieChart(null, dataset, false, true, false);
    PiePlot pieplot = (PiePlot) jfreechart.getPlot();
    if (colors != null) {
        for (int i = 0; i < colors.length; i++) {
            pieplot.setSectionPaint(dataset.getKey(i), colors[i]);
        }
    }
    pieplot.setBackgroundPaint(null);
    pieplot.setOutlineStroke(null);
    pieplot.setLabelGenerator(null);
    pieplot.setNoDataMessage(UILabels.STL40001_ERROR_No_DATA.getDescription());
    pieplot.setCircular(true);
    pieplot.setInteriorGap(0.000001);
    return jfreechart;
}

From source file:org.jajuk.ui.views.StatView.java

/**
 * Device size pie./*from w  w  w.  j ava  2s  .  c  o m*/
 * 
 * @return the chart
 */
private ChartPanel createDeviceRepartition() {
    try {
        DefaultPieDataset pdata = null;
        JFreeChart jfchart = null;
        // data
        pdata = new DefaultPieDataset();
        // prepare devices
        long lTotalSize = 0;
        double dOthers = 0;
        List<Device> devices = DeviceManager.getInstance().getDevices();
        long[] lSizes = new long[DeviceManager.getInstance().getElementCount()];
        ReadOnlyIterator<File> it = FileManager.getInstance().getFilesIterator();
        while (it.hasNext()) {
            File file = it.next();
            lTotalSize += file.getSize();
            lSizes[devices.indexOf(file.getDirectory().getDevice())] += file.getSize();
        }
        for (Device device : devices) {
            long lSize = lSizes[devices.indexOf(device)];
            if (lTotalSize > 0 && (double) lSize / lTotalSize < 0.05) {
                // less than 5% -> go to others
                dOthers += lSize;
            } else {
                double dValue = Math.round((double) lSize / 1073741824);
                pdata.setValue(device.getName(), dValue);
            }
        }
        if (dOthers > 0) {
            double dValue = Math.round((dOthers / 1073741824));
            pdata.setValue(Messages.getString("StatView.3"), dValue);
        }
        // chart
        jfchart = ChartFactory.createPieChart3D(Messages.getString("StatView.4"), pdata, true, true, true);
        // set the background color for the chart...
        PiePlot plot = (PiePlot) jfchart.getPlot();
        plot.setLabelFont(PiePlot.DEFAULT_LABEL_FONT);
        plot.setNoDataMessage(Messages.getString("StatView.5"));
        plot.setForegroundAlpha(0.5f);
        plot.setBackgroundAlpha(0.5f);
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1} GB ({2})"));
        plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} = {1} GB ({2})"));
        return new ChartPanel(jfchart);
    } catch (RuntimeException e) {
        Log.error(e);
        return null;
    }
}

From source file:org.jajuk.ui.views.StatView.java

/**
 * Genre repartition pie.// w w  w  .  ja va  2  s.com
 * 
 * @return the chart
 */
private ChartPanel createGenreRepartition() {
    try {
        DefaultPieDataset pdata = null;
        JFreeChart jfchart = null;
        // data
        pdata = new DefaultPieDataset();
        int iTotal = TrackManager.getInstance().getElementCount();
        double dOthers = 0;
        // Prepare a map genre -> nb tracks
        Map<Genre, Integer> genreNbTracks = new HashMap<Genre, Integer>(
                GenreManager.getInstance().getElementCount());
        ReadOnlyIterator<Track> it = TrackManager.getInstance().getTracksIterator();
        while (it.hasNext()) {
            Track track = it.next();
            Genre genre = track.getGenre();
            Integer nbTracks = genreNbTracks.get(genre);
            if (nbTracks == null) {
                genreNbTracks.put(genre, 1);
            } else {
                genreNbTracks.put(genre, nbTracks + 1);
            }
        }
        // Cleanup genre with weight < 5 %
        for (Map.Entry<Genre, Integer> entry : genreNbTracks.entrySet()) {
            double d = entry.getValue();
            if (iTotal > 0 && d / iTotal < Conf.getFloat(CONF_STATS_MIN_VALUE_GENRE_DISPLAY) / 100) {
                // less than 5% -> go to others
                dOthers += d;
            } else {
                double dValue = Math.round(100 * (d / iTotal));
                pdata.setValue(entry.getKey().getName2(), dValue);
            }
        }
        if (iTotal > 0 && dOthers > 0) {
            double dValue = Math.round(100 * (dOthers / iTotal));
            pdata.setValue(Messages.getString("StatView.0"), dValue);
        }
        // chart
        jfchart = ChartFactory.createPieChart3D(Messages.getString("StatView.1"), pdata, true, true, true);
        // set the background color for the chart...
        PiePlot plot = (PiePlot) jfchart.getPlot();
        plot.setLabelFont(PiePlot.DEFAULT_LABEL_FONT);
        plot.setNoDataMessage(Messages.getString("StatView.2"));
        plot.setForegroundAlpha(0.5f);
        plot.setBackgroundAlpha(0.5f);
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {2}"));
        plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} = {2}"));
        return new ChartPanel(jfchart);
    } catch (RuntimeException e) {
        Log.error(e);
        return null;
    }
}

From source file:aplicarFiltros.PanelResultado.java

public void graficar() {

    //Grafico de cantidad de Pixeles
    JFreeChart chartPixel = ChartFactory.createPieChart("Clasificacin", datasetPixel, true, true, false);
    chartPixel.setBackgroundPaint(Color.ORANGE);
    PiePlot plotPixel = (PiePlot) chartPixel.getPlot();
    //Color de las etiquetas
    plotPixel.setLabelBackgroundPaint(Color.ORANGE);
    //Color de el fondo del grfico
    plotPixel.setBackgroundPaint(Color.WHITE);
    plotPixel.setNoDataMessage("No hay data");

    ChartPanel panelPixel = new ChartPanel(chartPixel);
    final JPanel contentPixel = new JPanel(new BorderLayout());
    contentPixel.add(panelPixel);// ww w.ja  va  2s .c om
    //panelPixel.setPreferredSize(new java.awt.Dimension(500, 250));
    panelGraficoPixel.setPreferredSize(new java.awt.Dimension(500, 180));

    this.panelGraficoPixel.setLayout(new BorderLayout());
    this.panelGraficoPixel.add(contentPixel);
    contentPixel.setVisible(true);
    this.panelGraficoPixel.setVisible(true);
}

From source file:com.opensourcestrategies.activities.reports.ActivitiesChartsService.java

private String createPieChart(DefaultPieDataset dataset, String title)
        throws InfrastructureException, IOException {
    Debug.logInfo("Charting dashboard [" + title + "]", MODULE);
    // set up the chart
    JFreeChart chart = ChartFactory.createPieChart(title, dataset, true, // include legend
            true, // tooltips
            false // urls
    );//from  w  w  w. j av a  2 s .  com
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    // get a reference to the plot for further customization...
    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setCircular(true);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}: {1} / {2}",
            NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data available");

    Color[] colors = {
            Color.decode("#" + infrastructure.getConfigurationValue(
                    OpentapsConfigurationTypeConstants.ACTIVITIES_DASHBOARD_LEADS_NEW_COLOR)),
            Color.decode("#" + infrastructure.getConfigurationValue(
                    OpentapsConfigurationTypeConstants.ACTIVITIES_DASHBOARD_LEADS_OLD_COLOR)),
            Color.decode("#" + infrastructure.getConfigurationValue(
                    OpentapsConfigurationTypeConstants.ACTIVITIES_DASHBOARD_LEADS_NO_ACTIVITY_COLOR)) };
    for (int i = 0; i < dataset.getItemCount(); i++) {
        Comparable<?> key = dataset.getKey(i);
        plot.setSectionPaint(key, colors[i]);
    }

    // save as a png and return the file name
    return ServletUtilities.saveChartAsPNG(chart, chartWidth, chartHeight, null);
}