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:org.jfree.chart.demo.FirstDemo.java

public static void main(String args[]) {
    DefaultPieDataset defaultpiedataset = new DefaultPieDataset();
    defaultpiedataset.setValue("Category 1", 43.200000000000003D);
    defaultpiedataset.setValue("Category 2", 27.899999999999999D);
    defaultpiedataset.setValue("Category 3", 79.5D);
    org.jfree.chart.JFreeChart jfreechart = ChartFactory.createPieChart("Sample Pie Chart", defaultpiedataset,
            true, true, false);/*from   www.j a  v a  2 s  . co m*/
    ChartFrame chartframe = new ChartFrame("First", jfreechart);
    chartframe.pack();
    chartframe.setVisible(true);
}

From source file:urbanchart.java

public static void main(String[] arg) {
    final DefaultPieDataset data = new DefaultPieDataset();
    data.setValue("Housing(35%)($1050)", new Double(35));
    data.setValue("Debt(15%)($450)", new Double(15));
    data.setValue("transportation(15%)($450)", new Double(15));
    data.setValue("Food(15%)($450)", new Double(25));
    data.setValue("Saving(10%)($300)", new Double(10));
    JFreeChart chart = ChartFactory.createPieChart(
            "Average Distribution of expenses on income assuming 3000$/month (Urban areas)", data, true, true,
            false);//from w ww .  jav a2s  .  com
    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
    final File file1 = new File("E:\\java projects\\hackathon1\\web\\piecharturban.jpg");
    try {
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
    } catch (IOException ex) {
        Logger.getLogger(urbanchart.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:chart.PieChart3D.java

public static void main(String[] args) throws Exception {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("IPhone 5s", new Double(20));
    dataset.setValue("SamSung Grand", new Double(20));
    dataset.setValue("MotoG", new Double(40));
    dataset.setValue("Nokia Lumia", new Double(10));

    JFreeChart chart = ChartFactory.createPieChart3D("Mobile Sales", // chart title                   
            dataset, // data 
            true, // include legend                   
            true, false);/*from   w  ww  .j a v a  2s  .  com*/

    final PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setStartAngle(270);
    plot.setForegroundAlpha(0.60f);
    plot.setInteriorGap(0.02);
    int width = 640; /* Width of the image */
    int height = 480; /* Height of the image */
    File pieChart3D = new File("pie_Chart3D.jpeg");
    ChartUtilities.saveChartAsJPEG(pieChart3D, chart, width, height);
}

From source file:statistique.PieChart3D.java

public static void main(String[] args) throws Exception {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("IPhone 5s", new Double(20));
    dataset.setValue("SamSung Grand", new Double(20));
    dataset.setValue("MotoG", new Double(40));
    dataset.setValue("Nokia Lumia", new Double(10));

    JFreeChart chart = ChartFactory.createPieChart3D("Mobile Sales", // chart title                   
            dataset, // data 
            true, // include legend                   
            true, false);/*www  .java  2s.c  om*/

    final PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setStartAngle(270);
    plot.setForegroundAlpha(0.60f);
    plot.setInteriorGap(0.02);
    int width = 640; /* Width of the image */
    int height = 480; /* Height of the image */
    File pieChart3D = new File("pie_Chart3D.png");
    ChartUtilities.saveChartAsPNG(pieChart3D, chart, width, height);
}

From source file:ruralchart.java

public static void main(String[] arg) {
    final DefaultPieDataset data = new DefaultPieDataset();
    data.setValue("Housing(35%)($350)", new Double(35));
    data.setValue("Debt(15%)($150)", new Double(15));
    data.setValue("transportation(15%)($150)", new Double(15));
    data.setValue("Food(15%)($250)", new Double(25));
    data.setValue("Saving(10%)($100)", new Double(10));
    JFreeChart chart = ChartFactory.createPieChart(
            "Average Distribution of expenses on income assuming 1000$/month (Rural areas)", data, true, true,
            false);//from   w  w  w . ja v  a2s. c  o m
    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
    final File file1 = new File("E:\\java projects\\hackathon1\\web\\piechartrural.jpg");
    try {
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
    } catch (IOException ex) {
        Logger.getLogger(urbanchart.class.getName()).log(Level.SEVERE, null, ex);
    }

}

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

public static void main(String args[]) throws IOException {
    DefaultPieDataset defaultpiedataset = new DefaultPieDataset();
    defaultpiedataset.setValue("A", 1.0D);
    defaultpiedataset.setValue("B", 2D);
    defaultpiedataset.setValue("C", 3D);
    JFreeChart jfreechart = ChartFactory.createPieChart("Test", defaultpiedataset, true, false, false);
    LegendTitle legendtitle = jfreechart.getLegend();
    legendtitle.setMargin(0.0D, 0.0D, 1.0D, 1.0D);
    BufferedImage bufferedimage = new BufferedImage(1, 1, 2);
    Graphics2D graphics2d = bufferedimage.createGraphics();
    Size2D size2d = legendtitle.arrange(graphics2d);
    graphics2d.dispose();//  ww w .  ja  v a  2s  .  com
    int i = (int) Math.rint(size2d.width);
    int j = (int) Math.rint(size2d.height);
    BufferedImage bufferedimage1 = new BufferedImage(i, j, 2);
    Graphics2D graphics2d1 = bufferedimage1.createGraphics();
    legendtitle.draw(graphics2d1, new java.awt.geom.Rectangle2D.Double(0.0D, 0.0D, i, j));
    graphics2d1.dispose();
    BufferedOutputStream bufferedoutputstream = new BufferedOutputStream(
            new FileOutputStream(new File("LegendTitleToImageDemo1.png")));
    ChartUtilities.writeBufferedImageAsPNG(bufferedoutputstream, bufferedimage1);
    bufferedoutputstream.close();
}

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

public static void main(String args[]) throws IOException {
    DefaultPieDataset defaultpiedataset = new DefaultPieDataset();
    defaultpiedataset.setValue("England", 1.0D);
    defaultpiedataset.setValue("France", 2D);
    defaultpiedataset.setValue("Germany", 3D);
    defaultpiedataset.setValue("Italy", 4D);
    defaultpiedataset.setValue("Scotland", 5D);
    defaultpiedataset.setValue("Belgium", 6D);
    defaultpiedataset.setValue("Poland", 7D);
    defaultpiedataset.setValue("Spain", 8D);
    defaultpiedataset.setValue("Portugal", 9D);
    defaultpiedataset.setValue("Switzerland", 10D);
    defaultpiedataset.setValue("Austria", 11D);
    defaultpiedataset.setValue("Luxembourg", 12D);
    JFreeChart jfreechart = ChartFactory.createPieChart("Test", defaultpiedataset, true, false, false);
    LegendTitle legendtitle = jfreechart.getLegend();
    legendtitle.setMargin(0.0D, 0.0D, 1.0D, 1.0D);
    BufferedImage bufferedimage = new BufferedImage(1, 1, 2);
    Graphics2D graphics2d = bufferedimage.createGraphics();
    Size2D size2d = legendtitle.arrange(graphics2d, new RectangleConstraint(250D, new Range(0.0D, 10000D)));
    graphics2d.dispose();//from  w w  w . j  av a  2s  .c o  m
    int i = (int) Math.rint(size2d.width);
    int j = (int) Math.rint(size2d.height);
    BufferedImage bufferedimage1 = new BufferedImage(i, j, 2);
    Graphics2D graphics2d1 = bufferedimage1.createGraphics();
    legendtitle.draw(graphics2d1, new java.awt.geom.Rectangle2D.Double(0.0D, 0.0D, i, j));
    graphics2d1.dispose();
    BufferedOutputStream bufferedoutputstream = new BufferedOutputStream(
            new FileOutputStream(new File("LegendTitleToImageDemo2.png")));
    ChartUtilities.writeBufferedImageAsPNG(bufferedoutputstream, bufferedimage1);
    bufferedoutputstream.close();
}

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

/**
 * The starting point for the demo./* w  w w .  ja  v a2s .co m*/
 *
 * @param args  ignored.
 */
public static void main(final String[] args) {

    // create a dataset...
    final DefaultPieDataset data = new DefaultPieDataset();
    data.setValue("Category 1", 43.2);
    data.setValue("Category 2", 27.9);
    data.setValue("Category 3", 79.5);

    // create a chart...
    final JFreeChart chart = ChartFactory.createPieChart("Sample Pie Chart", data, true, // legend?
            true, // tooltips?
            false // URLs?
    );

    // create and display a frame...
    final ChartFrame frame = new ChartFrame("First", chart);
    frame.pack();
    frame.setVisible(true);

}

From source file:History.PieChart_DB.java

public static void main(String[] args) throws Exception {

    String mobilebrands[] = { "IPhone 5s", "SamSung Grand", "MotoG", "Nokia Lumia" };
    int statOfRepair = 0;
    java.util.Date now = new java.util.Date();
    String adminDate = (now.getYear() + 1900) + "-" + (now.getMonth() + 1) + "-" + now.getDate();
    /* Create MySQL Database Connection */
    Class.forName("com.mysql.jdbc.Driver");
    Connection connect = ConnectDatabase.connectDb("win", "win016");

    Statement statement = connect.createStatement();
    ResultSet resultSet = statement
            .executeQuery("SELECT COUNT(transID) AS statRepair FROM `Transaction` WHERE dateTime LIKE \'"
                    + adminDate + "%\' AND action LIKE 'Repair'");
    DefaultPieDataset dataset = new DefaultPieDataset();

    while (resultSet.next()) {
        dataset.setValue(resultSet.getString("statRepair"),
                Double.parseDouble(resultSet.getString("unit_sale")));
    }/*from   w  w w.j  a v a 2s . c o m*/

    JFreeChart chart = ChartFactory.createPieChart("History", // chart title           
            dataset, // data           
            true, // include legend          
            true, false);

    int width = 560; /* Width of the image */
    int height = 370; /* Height of the image */
    File pieChart = new File("Pie_Chart.jpeg");
    ChartUtilities.saveChartAsJPEG(pieChart, chart, width, height);
}

From source file:id.aas.apps.mvc.view.pieChart.java

public static void main(String[] args) throws SQLException {
    //        pieChart p = new pieChart();
    //        p.setVisible(true);
    //        p.run();
    EventQueue.invokeLater(new Runnable() {
        @Override/*ww  w.ja  va 2 s  .  c  o m*/
        public void run() {
            try {
                int nilaiKiloan = 0;
                int nilaiSatuan = 0;

                pieChart frame = new pieChart();
                frame.setVisible(true);
                String queryKiloan = "SELECT COUNT(*) FROM laundry WHERE jenis_layanan='Laundry Kiloan'";
                String querySatuan = "SELECT COUNT(*) FROM laundry WHERE jenis_layanan='Laundry Satuan'";
                ConnectionDB.InstanceDB.openConnection();
                ResultSet rs = ConnectionDB.InstanceDB.RunSelectQuery(queryKiloan);
                while (rs.next()) {
                    nilaiKiloan = rs.getInt(1);
                }
                System.out.println(nilaiKiloan);

                ResultSet rs1 = ConnectionDB.InstanceDB.RunSelectQuery(querySatuan);
                while (rs1.next()) {
                    nilaiSatuan = rs1.getInt(1);
                }
                System.out.println(nilaiSatuan);
                DefaultPieDataset pieDataset = new DefaultPieDataset();
                pieDataset.setValue("Laundry Kiloan", nilaiKiloan);
                pieDataset.setValue("Laundry Satuan", nilaiSatuan);

                JFreeChart chart = ChartFactory.createPieChart3D("Perbandingan Pengguna Layanan Laundry",
                        pieDataset, true, true, false);
                ChartPanel cPanel = new ChartPanel(chart);
                frame.setContentPane(cPanel);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}