Example usage for org.jfree.chart ChartFactory createPieChart3D

List of usage examples for org.jfree.chart ChartFactory createPieChart3D

Introduction

In this page you can find the example usage for org.jfree.chart ChartFactory createPieChart3D.

Prototype

public static JFreeChart createPieChart3D(String title, PieDataset dataset, boolean legend, boolean tooltips,
        boolean urls) 

Source Link

Document

Creates a 3D pie chart using the specified dataset.

Usage

From source file:fuel.gui.stats.StationStatsPanel.java

private void refreshGraphs() {
    graphContainer.removeAll();//from w w  w. j  ava2s.c o m
    DefaultPieDataset usageDataset = new DefaultPieDataset();
    try {
        for (Station station : database.getStations()) {
            ResultSet thisStation = database
                    .Query("SELECT SUM(liter) FROM fuelrecords WHERE stationId = " + station.getId(), true);
            thisStation.next();
            usageDataset.setValue(station.toString(), thisStation.getInt("1"));
        }

    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause());
    }
    JFreeChart usagePieChart = ChartFactory.createPieChart3D("", usageDataset, true, true, false);
    PiePlot3D plot3 = (PiePlot3D) usagePieChart.getPlot();
    plot3.setForegroundAlpha(0.6f);
    //plot3.setCircular(true);

    JPanel usagePieChartPanel = new ChartPanel(usagePieChart);
    usagePieChartPanel.setBorder(
            BorderFactory.createTitledBorder(BorderFactory.createTitledBorder("Tankstation verhouding")));
    usagePieChartPanel.setPreferredSize(new java.awt.Dimension(320, 240));

    DefaultPieDataset fuelDataset = new DefaultPieDataset();
    try {
        ResultSet numberResults = database.Query("SELECT DISTINCT typeOfGas FROM fuelrecords", true);
        while (numberResults.next()) {
            ResultSet thisStation = database.Query("SELECT SUM(liter) FROM fuelrecords WHERE typeOfGas = '"
                    + numberResults.getString("typeOfGas") + "'", true);
            thisStation.next();
            fuelDataset.setValue(numberResults.getString("typeOfGas"), thisStation.getInt("1"));
        }

    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause());
    }
    JFreeChart fuelPieChart = ChartFactory.createPieChart3D("", fuelDataset, true, true, false);
    PiePlot3D plot2 = (PiePlot3D) fuelPieChart.getPlot();
    plot2.setForegroundAlpha(0.6f);
    //plot3.setCircular(true);

    JPanel fuelPieChartPanel = new ChartPanel(fuelPieChart);
    fuelPieChartPanel.setBorder(
            BorderFactory.createTitledBorder(BorderFactory.createTitledBorder("Brandstof verhouding")));
    fuelPieChartPanel.setPreferredSize(new java.awt.Dimension(320, 240));

    DefaultCategoryDataset barDataset = new DefaultCategoryDataset();
    try {
        ResultSet motorThing = database.Query("SELECT cost/liter,date FROM fuelrecords ORDER BY date ASC",
                true);
        while (motorThing.next()) {
            barDataset.addValue(motorThing.getDouble("1"), motorThing.getString("date"), "Prijs per liter");
        }

    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause());
    }

    JFreeChart barChart = ChartFactory.createBarChart3D("", // chart title
            "", // domain axis label
            "Aantal", // range axis label
            barDataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips?
            false // URLs?
    );
    CategoryPlot plot = barChart.getCategoryPlot();
    BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    ChartPanel barChartPanel = new ChartPanel(barChart);
    barChartPanel.getChartRenderingInfo().setEntityCollection(null);
    barChartPanel.setBorder(BorderFactory.createTitledBorder("Prijs per liter"));
    barChartPanel.setPreferredSize(new java.awt.Dimension(320, 240));

    JPanel piePanel = new JPanel(new GridLayout(0, 2));
    piePanel.add(usagePieChartPanel);
    piePanel.add(fuelPieChartPanel);
    graphContainer.add(piePanel);
    graphContainer.add(barChartPanel);
    revalidate();
    repaint();
}

From source file:vn.edu.vttu.ui.PanelStatiticsService.java

private void showChart() {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    DefaultPieDataset dataset = new DefaultPieDataset();
    int row = tbResult.getRowCount();
    for (int i = 0; i < row; i++) {
        totalNumber = totalNumber + Integer.parseInt(String.valueOf(tbResult.getValueAt(i, 3)));
    }//from w  w  w  .ja v  a2  s  . c  o  m
    for (int i = 0; i < row; i++) {
        double value = 0;
        try {
            try {
                value = Double
                        .parseDouble(String.valueOf(tbResult.getValueAt(i, 3)).trim().replaceAll("\\.", ""));
            } catch (Exception e) {
                value = Double
                        .parseDouble(String.valueOf(tbResult.getValueAt(i, 3)).trim().replaceAll(",", ""));
            }
        } catch (Exception e) {
            value = 0;
        }
        String name = String.valueOf(tbResult.getValueAt(i, 1)).trim();
        DecimalFormat df = new DecimalFormat("###,##");
        value = (value / totalNumber) * 100;
        System.out.println(totalNumber);
        dataset.setValue(name, value);
    }

    JFreeChart chart = ChartFactory.createPieChart3D("TH?NG K T L S DNG DCH V", dataset,
            true, true, true);
    PiePlot3D p = (PiePlot3D) chart.getPlot();
    p.setNoDataMessage("Khng c d liu thng k");
    ChartPanel CP = new ChartPanel(chart);
    pnChart.removeAll();
    pnChart.add(CP);
    pnChart.updateUI();
    pnChart.repaint();
    //ChartFrame frame = new ChartFrame("Thng k doanh thu", chart);
    //frame.setSize(450, 350);
    //frame.setVisible(true);
}

From source file:de.suse.swamp.test.TestStatisticsGraph.java

public void testStatistic() {

    XYSeries series = new XYSeries("Running Workflows");
    series.add(1995, 0.5);//from  w w w . j  a  v a  2  s  . c o  m
    series.add(2000, 3.0);
    series.add(2010, 20.0);
    series.add(2020, 50.0);
    XYDataset dataset = new XYSeriesCollection(series);

    JFreeChart chart = ChartFactory.createTimeSeriesChart("test", "time", "value", dataset, false, false,
            false);

    JFreeChart chart4;
    DefaultPieDataset dataset2 = new DefaultPieDataset();
    // Initialize the dataset
    dataset2.setValue("California", new Double(10.0));
    dataset2.setValue("Arizona", new Double(8.0));
    dataset2.setValue("New Mexico", new Double(8.0));
    dataset2.setValue("Texas", new Double(40.0));
    dataset2.setValue("Louisiana", new Double(8.0));
    dataset2.setValue("Mississippi", new Double(4.0));
    dataset2.setValue("Alabama", new Double(2.0));
    dataset2.setValue("Florida", new Double(20.0));

    chart4 = ChartFactory.createPieChart3D("Driving Time Spent Per State (3D with Transparency)", // The chart title
            dataset2, // The dataset for the chart
            true, // Is a legend required?
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );
    PiePlot3D plot4 = (PiePlot3D) chart4.getPlot();
    plot4.setForegroundAlpha(0.6f);

    try {
        ChartUtilities.saveChartAsPNG(new java.io.File("test.png"), chart, 500, 300);

        ChartUtilities.saveChartAsPNG(new java.io.File("test2.png"), chart4, 500, 300);
    } catch (java.io.IOException exc) {
        System.err.println("Error writing image to file");
    }

}

From source file:edu.wpi.cs.wpisuitetng.modules.requirementsmanager.view.charts.AbstractRequirementStatistics.java

protected JFreeChart buildPieChart(final String title) {
    return ChartFactory.createPieChart3D(title, toPieDataset(), true, false, false);
}

From source file:org.mt4jx.components.visibleComponents.widgets.jfreechart.examples.MTJFreeChartExampleScene.java

public MTJFreeChartExampleScene(MTApplication mtApplication, String name) {
    super(mtApplication, name);
    this.setClearColor(new MTColor(0, 0, 96, 255));
    //Show touches
    this.registerGlobalInputProcessor(new CursorTracer(mtApplication, this));

    // Create Example Data
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0; i < 10; i++) {
        dataset.addValue(10 * Math.random(), "MySeries", "T" + i);
    }/*from   w w  w  .  j av a2s.c  o m*/
    // Create a JFreeChart
    JFreeChart chart1 = ChartFactory.createLineChart("Line Chart", "x axis", "y axis", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    // Put the JFreeChart into a MTJFreeChart wrapper
    MTJFreeChart mtChart1 = new MTJFreeChart(800, 600, mtApplication, chart1);

    // Create another chart
    DefaultPieDataset pds = new DefaultPieDataset();

    pds.setValue("Java", new Double(17.773));
    pds.setValue("C", new Double(15.822));
    pds.setValue("C++", new Double(8.783));
    pds.setValue("PHP", new Double(7.835));
    pds.setValue("Python", new Double(6.265));
    pds.setValue("C#", new Double(6.226));
    pds.setValue("(Visual) Basic", new Double(5.867));
    pds.setValue("Objective-C", new Double(3.011));
    pds.setValue("Perl", new Double(2.857));

    JFreeChart chart2 = ChartFactory.createPieChart3D(
            "Top 10: TIOBE Programming Community Index\nfor January 2011 (www.tiobe.com)", pds, true, true,
            Locale.GERMANY);
    PiePlot3D plot = (PiePlot3D) chart2.getPlot();
    plot.setStartAngle(290);

    MTJFreeChart mtChart2 = new MTJFreeChart(800, 600, mtApplication, chart2);
    // enable redraw of the chart when it's scaled by the user
    mtChart2.setRedrawWhenScaled(true);
    this.getCanvas().addChild(mtChart1);
    this.getCanvas().addChild(mtChart2);
    mtChart1.setPositionGlobal(new Vector3D(mtApplication.width / 2f, mtApplication.height / 2f));
    mtChart2.setPositionGlobal(new Vector3D(150 + mtApplication.width / 2f, 150 + mtApplication.height / 2f));
}

From source file:biz.ixnay.pivot.charts.skin.jfree.PieChartViewSkin.java

@Override
protected JFreeChart createChart() {
    PieChartView chartView = (PieChartView) getComponent();

    String title = chartView.getTitle();
    boolean showLegend = chartView.getShowLegend();

    ChartView.CategorySequence categories = chartView.getCategories();
    String seriesNameKey = chartView.getSeriesNameKey();
    List<?> chartData = chartView.getChartData();

    JFreeChart chart;//  w  ww. ja v  a  2 s  .com
    if (threeDimensional) {
        if (chartData.getLength() > 1) {
            CategorySeriesDataset dataset = new CategorySeriesDataset(categories, seriesNameKey, chartData);

            chart = ChartFactory.createMultiplePieChart3D(title, dataset, TableOrder.BY_ROW, showLegend, false,
                    false);
        } else {
            PieSeriesDataset dataset = new PieSeriesDataset(categories, chartData.get(0));
            chart = ChartFactory.createPieChart3D(title, dataset, showLegend, false, false);

            PiePlot3D plot = (PiePlot3D) chart.getPlot();
            plot.setDarkerSides(darkerSides);
            plot.setDepthFactor(depthFactor);
        }
    } else {
        if (chartData.getLength() > 1) {
            CategorySeriesDataset dataset = new CategorySeriesDataset(categories, seriesNameKey, chartData);

            chart = ChartFactory.createMultiplePieChart(title, dataset, TableOrder.BY_ROW, showLegend, false,
                    false);
        } else {
            PieSeriesDataset dataset = new PieSeriesDataset(categories, chartData.get(0));
            chart = ChartFactory.createPieChart(title, dataset, showLegend, false, false);

            HashMap<String, String> categoryLabels = new HashMap<String, String>();
            for (int i = 0, n = categories.getLength(); i < n; i++) {
                ChartView.Category category = categories.get(i);
                categoryLabels.put(category.getKey(), category.getLabel());
            }

            PiePlot plot = (PiePlot) chart.getPlot();
            for (String categoryKey : explodePercentages) {
                plot.setExplodePercent(categoryLabels.get(categoryKey),
                        explodePercentages.get(categoryKey).doubleValue());
            }
        }
    }

    return chart;
}

From source file:com.netsteadfast.greenstep.action.CommonPieChartAction.java

private void fillChart(String title, List<String> names, List<String> colors, List<Float> values)
        throws Exception {
    DefaultPieDataset data = new DefaultPieDataset();
    for (int ix = 0; ix < names.size(); ix++) {
        data.setValue(names.get(ix), values.get(ix));
    }/*from w ww .j a v a 2s  . c  o m*/
    this.chart = ChartFactory.createPieChart3D(title, data, true, true, false);
    LegendTitle legend = this.chart.getLegend();
    legend.setItemFont(new Font("", Font.TRUETYPE_FONT, 9));
    PiePlot plot = (PiePlot) this.chart.getPlot();
    plot.setCircular(true);
    plot.setBackgroundAlpha(0.9f);
    plot.setForegroundAlpha(0.5f);
    plot.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9));
    this.setPlotColor(plot, names, colors);
    this.chart.setTitle(new TextTitle(title, new Font("", Font.TRUETYPE_FONT, 9)));
}

From source file:org.jtheque.films.stats.view.impl.panels.PanelStats.java

/**
 * Create a panel containing a pie chart.
 *
 * @param key     The i18 key of the title of the pie chart.
 * @param dataset The dataset used to populate the pie chart.
 *
 * @return The component containing the pie chart.
 *///from ww  w  .  j  a  v a 2 s  .  c om
final Component createPieChartPanel(String key, PieDataset dataset) {
    JFreeChart pie = ChartFactory.createPieChart3D(resources.getMessage(key), dataset, true, true, true);

    pie.getLegend().setLegendItemGraphicLocation(RectangleAnchor.RIGHT);

    Managers.getManager(ILanguageManager.class).addInternationalizable(new InternationalizableChart(pie, key));

    Component chartPanel = new ChartPanel(pie);

    chartPanel.setBackground(Color.white);

    return chartPanel;
}

From source file:teambootje.A5.java

/**
 * Creates new form A5/*from  ww w.  j  a  v  a  2s  .c om*/
 */
public A5() {
    initComponents();
    setLocationRelativeTo(null);
    setLayout(new BorderLayout());

    //Create and set up the window.
    setTitle("SS Rotterdam Analyse || Analyse 5");
    ImageIcon icon = new ImageIcon("img/bootje.jpg");
    setIconImage(icon.getImage());

    // back BTN
    JButton back = new JButton("Back");
    add(back, BorderLayout.NORTH);

    back.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
            // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });

    // panel en Label
    JPanel ana = new JPanel();
    add(ana, BorderLayout.CENTER);

    //tabel
    String sql = "SELECT Leeftijd, COUNT(*) AS Aantal FROM persoon GROUP BY Leeftijd";
    List<Object[]> list = new ArrayList<Object[]>();
    ResultSet rs = null;
    try {
        rs = db.runSql(sql);
        while (rs.next()) {
            String age = rs.getString("Leeftijd");
            int aantal = rs.getInt("Aantal");
            String[] row = new String[rs.getMetaData().getColumnCount()];
            for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
                row[i - 1] = rs.getString(i);
            }
            list.add(row);

            //chart
            JButton chart = new JButton("Chart");
            add(chart, BorderLayout.SOUTH);

            chart.addActionListener(new ActionListener() {
                String leeftijd = age;
                int a1 = aantal;

                @Override
                public void actionPerformed(ActionEvent e) {

                    DefaultPieDataset pieDataset = new DefaultPieDataset();
                    pieDataset.setValue("Niet vrijgegeven", a1);

                    JFreeChart chart = ChartFactory.createPieChart3D("Aantal mensen per leeftijd", pieDataset,
                            true, true, true);
                    PiePlot3D p = (PiePlot3D) chart.getPlot();
                    //p.setForegroundAlpha(TOP_ALIGNMENT);
                    ChartFrame pie = new ChartFrame("Aantal mensen per leeftijd", chart);
                    pie.setVisible(true);
                    pie.setSize(500, 500);
                    pie.setLocationRelativeTo(null);

                    // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                }
            });
        }
    } catch (SQLException e) {
        JOptionPane.showMessageDialog(null, e);
    }

    Object[][] array = new Object[list.size()][];
    Object columnNames[] = { "Leeftijd", "Aantal" };
    list.toArray(array);

    JTable table = new JTable(array, columnNames);
    JScrollPane scroll = new JScrollPane(table);
    scroll.setPreferredSize(new Dimension(400, 400));
    ana.add(scroll);
}

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);// ww w . j  ava 2s  .  c om
    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;
}