Example usage for org.jfree.data.general DefaultPieDataset setValue

List of usage examples for org.jfree.data.general DefaultPieDataset setValue

Introduction

In this page you can find the example usage for org.jfree.data.general DefaultPieDataset setValue.

Prototype

public void setValue(Comparable key, double value) 

Source Link

Document

Sets the data value for a key and sends a DatasetChangeEvent to all registered listeners.

Usage

From source file:com.gallatinsystems.common.util.JFreechartChartUtil.java

/**
 * generates a pie chart with the set of labels and values passed in (the labels and values
 * arrays must both be non-null and contain the same number of elements). The chart is returned
 * as a byte array representing the image.
 * /*from  ww w .  j  a  va2  s  . c o m*/
 * @param labels
 * @param values
 * @param title
 * @param width
 * @param height
 * @return - byte array containing the image, null if there is an error.
 */
public static byte[] getPieChart(List<String> labels, List<String> values, String title, int width,
        int height) {
    DefaultPieDataset pieDataset = new DefaultPieDataset();

    for (int i = 0; i < labels.size(); i++) {
        pieDataset.setValue(labels.get(i) + " (" + values.get(i) + ")", Double.parseDouble(values.get(i)));
    }
    JFreeChart chart = ChartFactory.createPieChart(title, pieDataset, false, false, false);
    try {
        return ChartUtilities.encodeAsPNG(chart.createBufferedImage(width, height));
    } catch (Exception e) {
        e.printStackTrace(System.err);
        return null;
    }

}

From source file:org.jfree.chart.demo.XYDrawableAnnotationDemo1.java

private static JFreeChart createPieChart() {
    DefaultPieDataset defaultpiedataset = new DefaultPieDataset();
    defaultpiedataset.setValue("Engineering", 43.200000000000003D);
    defaultpiedataset.setValue("Research", 13.199999999999999D);
    defaultpiedataset.setValue("Advertising", 20.899999999999999D);
    PiePlot pieplot = new PiePlot(defaultpiedataset);
    pieplot.setBackgroundPaint(null);//from   ww w. ja v a2s  .c  o  m
    pieplot.setOutlinePaint(null);
    pieplot.setBaseSectionOutlinePaint(Color.white);
    pieplot.setBaseSectionOutlineStroke(new BasicStroke(2.0F));
    pieplot.setLabelFont(new Font("Dialog", 0, 18));
    pieplot.setMaximumLabelWidth(0.25D);
    JFreeChart jfreechart = new JFreeChart(pieplot);
    jfreechart.setBackgroundPaint(null);
    jfreechart.removeLegend();
    jfreechart.setPadding(RectangleInsets.ZERO_INSETS);
    return jfreechart;
}

From source file:org.jfree.chart.demo.selection.SelectionDemo6Pie.java

private static PieDataset createDataset() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("One", 43.2);
    dataset.setValue("Two", 10.0);
    dataset.setValue("Three", 27.5);
    dataset.setValue("Four", 17.5);
    dataset.setValue("Five", 11.0);
    dataset.setValue("Six", 19.4);
    return dataset;
}

From source file:graphic.Grafico.java

private static javax.swing.JPanel pizza3D(ArrayList nome, ArrayList valor, String tituloGrafico,
        float transparencia, String tipo) {
    DefaultPieDataset data = new DefaultPieDataset();

    for (int i = 0; i < nome.toArray().length; i++) {
        data.setValue("" + nome.get(i).toString(), new Double(valor.get(i).toString()));
    }/*  ww  w  . ja v a  2s . com*/

    JFreeChart chart = ChartFactory.createPieChart3D(tituloGrafico, data, true, true, true);

    java.awt.Color cor = new java.awt.Color(200, 200, 200);
    chart.setBackgroundPaint(cor);
    PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setLabelLinksVisible(true);
    plot.setNoDataMessage("No existem dados para serem exibidos no grfico");

    plot.setStartAngle(90);
    plot.setDirection(Rotation.CLOCKWISE);

    plot.setForegroundAlpha(transparencia);
    plot.setInteriorGap(0.20);

    ChartPanel chartPanel = new ChartPanel(chart);

    return chartPanel;
}

From source file:com.globalsight.util.JfreeCharUtil.java

private static PieDataset buildDatas(Map<String, Double> datas) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    for (String key : datas.keySet()) {
        dataset.setValue(key, datas.get(key));
    }//w ww.  ja v a2s . c  o  m
    return dataset;
}

From source file:frequencyassignment.charts.Charts.java

public static void displayPie(String name, HashMap<String, Double> categoryValue) {
    DefaultPieDataset data = new DefaultKeyedValuesDataset();
    for (Map.Entry<String, Double> entry : categoryValue.entrySet()) {
        data.setValue(entry.getKey(), entry.getValue());
    }/*  ww  w.  j  av  a2 s.c  o m*/
    JFreeChart chart = ChartFactory.createPieChart("Pie Chart", data, true, true, true);
    ChartFrame frame = new ChartFrame(name, chart);
    frame.pack();
    frame.setVisible(true);
}

From source file:br.com.ifpb.models.Grafico.java

/**
 * //from   w  ww.  j a  va2  s .c  o m
 * @param nome
 * @param valor
 * @param tituloGrafico
 * @param transparencia
 * @param tipo
 * @return 
 */
private static javax.swing.JPanel pizza3D(ArrayList nome, ArrayList valor, String tituloGrafico,
        float transparencia, String tipo) {

    DefaultPieDataset data = new DefaultPieDataset();

    for (int i = 0; i < nome.toArray().length; i++) {
        data.setValue("" + nome.get(i).toString(), new Double(valor.get(i).toString()));
    }

    JFreeChart chart = ChartFactory.createPieChart3D(tituloGrafico, data, true, true, true);
    java.awt.Color cor = new java.awt.Color(200, 200, 200);
    chart.setBackgroundPaint(cor);
    PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setLabelLinksVisible(true);
    plot.setNoDataMessage("No existem dados para serem exibidos ");

    plot.setStartAngle(90);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(transparencia);
    plot.setInteriorGap(0.20);

    ChartPanel chartPanel = new ChartPanel(chart);

    return chartPanel;
}

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

private static PieDataset createDataset() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("One", new Double(43.2));
    dataset.setValue("Two", new Double(10.0));
    dataset.setValue("Three", new Double(27.5));
    dataset.setValue("Four", new Double(17.5));
    dataset.setValue("Five", new Double(11.0));
    dataset.setValue("Six", new Double(19.4));
    return dataset;
}

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

private static PieDataset createPreviousDataset() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("One", new Double(45.2));
    dataset.setValue("Two", new Double(10.0));
    dataset.setValue("Three", new Double(20.5));
    dataset.setValue("Four", new Double(12.5));
    dataset.setValue("Five", new Double(31.0));
    dataset.setValue("Six", new Double(19.4));
    return dataset;
}

From source file:org.jfree.graphics2d.demo.SVGChartWithAnnotationsDemo1.java

private static JFreeChart createPieChart() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Engineering", 43.2);
    dataset.setValue("Research", 13.2);
    dataset.setValue("Advertising", 20.9);
    PiePlot plot = new PiePlot(dataset);
    plot.setBackgroundPainter(null);/*w ww.java 2 s  . co  m*/
    plot.setBorderPainter(null);
    plot.setBaseSectionOutlinePaint(Color.white);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));
    plot.setLabelFont(new Font("Dialog", Font.PLAIN, 18));
    plot.setMaximumLabelWidth(0.25);
    JFreeChart chart = new JFreeChart(plot);
    chart.setBackgroundPainter(null);
    chart.removeLegend();
    chart.setPadding(RectangleInsets.ZERO_INSETS);
    return chart;
}