Example usage for org.jfree.data.general DatasetUtilities createPieDatasetForColumn

List of usage examples for org.jfree.data.general DatasetUtilities createPieDatasetForColumn

Introduction

In this page you can find the example usage for org.jfree.data.general DatasetUtilities createPieDatasetForColumn.

Prototype

public static PieDataset createPieDatasetForColumn(CategoryDataset dataset, int column) 

Source Link

Document

Creates a pie dataset from a CategoryDataset by taking all the values for a single column.

Usage

From source file:net.sourceforge.processdash.ui.web.reports.DiscChart.java

public static JFreeChart createDiscChart(ResultSet data, Map parameters) {
    // data.sortBy(1, true);
    CategoryDataset catData = data.catDataSource();
    PieDataset pieData = null;//from  ww  w. ja  v  a2 s  .c  o  m
    if (catData.getColumnCount() == 1)
        pieData = DatasetUtilities.createPieDatasetForColumn(catData, 0);
    else
        pieData = DatasetUtilities.createPieDatasetForRow(catData, 0);

    DiscPlot plot = new DiscPlot(pieData);
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
    plot.setDrawingSupplier(DRAWING_SUPPLIER_FACTORY.newDrawingSupplier());
    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    if (parameters.get("skipItemLabels") != null || parameters.get("skipDiscLabels") != null)
        plot.setLabelGenerator(null);
    else if (parameters.get("discLabelFontSize") != null)
        try {
            float fontSize = Float.parseFloat((String) parameters.get("discLabelFontSize"));
            plot.setLabelFont(plot.getLabelFont().deriveFont(fontSize));
        } catch (Exception lfe) {
        }
    if (parameters.get("ellipse") != null)
        ((StandardDiscItemDistributor) plot.getDiscDistributor()).setCircular(false);

    String interiorGap = (String) parameters.get("interiorGap");
    if (interiorGap != null)
        try {
            plot.setInteriorGap(Integer.parseInt(interiorGap) / 100.0);
        } catch (NumberFormatException e) {
        }
    String interiorSpacing = (String) parameters.get("interiorSpacing");
    if (interiorSpacing != null)
        try {
            plot.setInteriorGap(Integer.parseInt(interiorSpacing) / 200.0);
        } catch (NumberFormatException e) {
        }

    return chart;
}

From source file:net.sourceforge.processdash.ui.web.reports.PieChart.java

/** Create a  line chart. */
@Override//from   www . j a  v a  2s.com
public JFreeChart createChart() {
    CategoryDataset catData = data.catDataSource();
    PieDataset pieData = null;
    if (catData.getColumnCount() == 1)
        pieData = DatasetUtilities.createPieDatasetForColumn(catData, 0);
    else
        pieData = DatasetUtilities.createPieDatasetForRow(catData, 0);

    JFreeChart chart = null;
    if (get3DSetting()) {
        chart = ChartFactory.createPieChart3D(null, pieData, true, true, false);
        chart.getPlot().setForegroundAlpha(ALPHA);
    } else {
        chart = ChartFactory.createPieChart(null, pieData, true, true, false);
    }

    PiePlot plot = (PiePlot) chart.getPlot();
    if (parameters.get("skipItemLabels") != null || parameters.get("skipWedgeLabels") != null)
        plot.setLabelGenerator(null);
    else if (parameters.get("wedgeLabelFontSize") != null)
        try {
            float fontSize = Float.parseFloat((String) parameters.get("wedgeLabelFontSize"));
            plot.setLabelFont(plot.getLabelFont().deriveFont(fontSize));
        } catch (Exception lfe) {
        }
    if (parameters.get("ellipse") != null)
        plot.setCircular(true);
    else
        plot.setCircular(false);

    Object colorScheme = parameters.get("colorScheme");
    if ("byPhase".equals(colorScheme))
        maybeConfigurePhaseColors(plot, pieData);
    else if ("consistent".equals(colorScheme))
        // since 2.0.9
        configureConsistentColors(plot, pieData);
    else if (parameters.containsKey("c1"))
        configureIndividualColors(plot, pieData);

    String interiorGap = (String) parameters.get("interiorGap");
    if (interiorGap != null)
        try {
            plot.setInteriorGap(Integer.parseInt(interiorGap) / 100.0);
        } catch (NumberFormatException e) {
        }
    String interiorSpacing = (String) parameters.get("interiorSpacing");
    if (interiorSpacing != null)
        try {
            plot.setInteriorGap(Integer.parseInt(interiorSpacing) / 200.0);
        } catch (NumberFormatException e) {
        }

    if (!parameters.containsKey("showZeroValues")) {
        plot.setIgnoreZeroValues(true);
        plot.setIgnoreNullValues(true);
    }

    return chart;
}

From source file:net.sourceforge.processdash.ui.web.reports.RadarChart.java

/** Create a radar chart. */
@Override//from w  ww .  jav  a  2  s. c  om
public JFreeChart createChart() {
    maybeScaleDataAxes();
    CategoryDataset catData = data.catDataSource();
    PieDataset pieData = null;
    if (catData.getRowCount() == 1)
        pieData = DatasetUtilities.createPieDatasetForRow(catData, 0);
    else
        pieData = DatasetUtilities.createPieDatasetForColumn(catData, 0);

    RadarPlot plot = new RadarPlot(pieData);
    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    if (parameters.get("skipAxisLabels") != null)
        plot.setShowAxisLabels(false);
    String interiorGap = getParameter("interiorGap");
    if (interiorGap != null)
        try {
            plot.setInteriorGap(Integer.parseInt(interiorGap) / 100.0);
        } catch (NumberFormatException e) {
        }
    String interiorSpacing = getParameter("interiorSpacing");
    if (interiorSpacing != null)
        try {
            plot.setInteriorGap(Integer.parseInt(interiorSpacing) / 200.0);
        } catch (NumberFormatException e) {
        }

    return chart;
}

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

/**
 * Creates and returns a sample pie chart.
 *
 * @return a sample pie chart.//from  www  .j  a  v  a2s  . co  m
 */
public JFreeChart createPieChartTwo() {

    // create a default chart based on some sample data...
    final String title = this.resources.getString("pie.pie2.title");
    final CategoryDataset data = DemoDatasetFactory.createCategoryDataset();
    final Comparable category = (Comparable) data.getColumnKeys().get(1);
    final PieDataset extracted = DatasetUtilities.createPieDatasetForColumn(data, category);
    final JFreeChart chart = ChartFactory.createPieChart(title, extracted, true, true, false);

    // then customise it a little...
    chart.setBackgroundPaint(Color.lightGray);
    final PiePlot pie = (PiePlot) chart.getPlot();
    pie.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    pie.setBackgroundImage(JFreeChart.INFO.getLogo());
    pie.setBackgroundPaint(Color.white);
    pie.setBackgroundAlpha(0.6f);
    pie.setForegroundAlpha(0.75f);
    return chart;

}

From source file:edu.uara.gui.tableeditor.ChartGenerationFrame.java

private void generateChart() {
    //generate Base Dataset (Category Dataset)
    if (datasetTable != null)
        this.generateBaseDataset();

    if (c != null) {
        if (this.splitPane.getTopComponent() == panel) {
            int option = JOptionPane.showConfirmDialog(this, "Create new chart?\r\n", "Warning",
                    JOptionPane.YES_NO_OPTION);
            if (option == JOptionPane.YES_OPTION) {
                if (this.cmd_saveChart.isEnabled()) {
                    int innerOption = JOptionPane.showConfirmDialog(this,
                            "Current chart is modified. Do you want to save?\r\n", "Warning",
                            JOptionPane.YES_NO_OPTION);
                    if (innerOption == JOptionPane.YES_OPTION)
                        this.saveFigure();
                }//from  ww  w .  j ava 2  s .  co m
                this.figure = null;
                this.splitPane.remove(panel);
            } else
                return;

        }
    }

    if (this.pieChartOption.isSelected()) {
        //get series
        PieDataset dataset = null;
        String series = this.cbo_pieDataSeries.getSelectedItem().toString();
        CustomPieChart ch = new CustomPieChart(txt_chartName.getText(), this.opt_legend.isSelected());//legend
        String tableOrder = cbo_pieDataSelect.getSelectedItem().toString();
        TableOrder tbOrder = null;
        if (tableOrder.equals("Row")) {
            tbOrder = TableOrder.BY_ROW;
        } else {
            tbOrder = TableOrder.BY_COLUMN;
        }

        if (this.opt_multiPieCharts.isSelected())//multiple piechart 
        {
            if (this.opt_effect3D.isSelected())
                ch.generateMultiple3DPieChart(baseDataset, tbOrder);
            else
                ch.generateMultiplePieChart(baseDataset, tbOrder);

            if (this.opt_exploded.isSelected()) {
                try {
                    ch.setExplodePercent(this.cbo_explodedSections.getSelectedItem().toString(),
                            Double.parseDouble(this.txt_explodedPercent.getText()));
                } catch (Exception ex) {
                    System.out.println("Error setting exploded section! " + ex.getMessage());
                }
            }
        } else {
            try {
                if (tbOrder == TableOrder.BY_ROW)
                    dataset = DatasetUtilities.createPieDatasetForRow(baseDataset, series);
                else
                    dataset = DatasetUtilities.createPieDatasetForColumn(baseDataset, series);
            } catch (Exception ex) {
                System.out.println("Error with pie dataset, default series is used");
                dataset = DatasetUtilities.createPieDatasetForRow(baseDataset, 0);
            }

            //ch.setIgnoreNullOrZeroValues(true);//ignore null values

            if (opt_effect3D.isSelected()) {
                ch.generate3DPieChart(dataset, series, tbOrder);
            } else {
                ch.generatePieChart(dataset, series, tbOrder);
                //edit exploded parts
                if (this.opt_exploded.isSelected()) {
                    try {
                        ch.setExplodePercent(this.cbo_explodedSections.getSelectedItem().toString(),
                                Double.parseDouble(this.txt_explodedPercent.getText()));
                    } catch (Exception ex) {
                        System.out.println("Error setting exploded section! " + ex.getMessage());
                    }
                }
            }
        }
        ch.setIgnoreNullOrZeroValues(true);//ignore null values
        int labelFormat = cbo_pieSectionLabel.getSelectedIndex();
        ch.setLabelFormat(labelFormat);
        c = ch;
        this.updateStatus("Pie chart has been generated.");
    } else if (this.lineChartOption.isSelected()) {
        // create a chart...
        PlotOrientation orientation;//options for orientation

        if (this.opt_layoutV.isSelected())
            orientation = PlotOrientation.VERTICAL;
        else if (this.opt_layoutH.isSelected())
            orientation = PlotOrientation.HORIZONTAL;
        else
            orientation = PlotOrientation.VERTICAL;

        CustomLineChart ch = new CustomLineChart(this.txt_chartName.getText(), this.txt_DomainLabel.getText(),
                this.txt_RangeLabel.getText(), orientation, this.opt_legend.isSelected());
        if (opt_effect3D.isSelected()) {
            ch.generate3DLineChart(baseDataset);
        } else {
            ch.generateLineChart(baseDataset);
        }

        //apply options
        if (this.opt_showGridline.isSelected()) {
            ch.setGridLineVisible(true);
        } else {
            ch.setGridLineVisible(false);
        }

        c = ch;
        this.updateStatus("Line chart has been generated.");
    } else if (this.BarChartOption.isSelected()) {
        // create a chart...
        PlotOrientation orientation;//options for orientation

        if (this.opt_layoutV.isSelected())
            orientation = PlotOrientation.VERTICAL;
        else if (this.opt_layoutH.isSelected())
            orientation = PlotOrientation.HORIZONTAL;
        else
            orientation = PlotOrientation.VERTICAL;

        CustomBarChart ch = new CustomBarChart(this.txt_chartName.getText(), this.txt_DomainLabel.getText(),
                this.txt_RangeLabel.getText(), orientation, opt_legend.isSelected());
        if (this.opt_subCategory.isSelected()) {
            ch.generateGroupBarChart(baseDataset, groupMap);
            ch.setSubCategoryAxis(txt_DomainLabel.getText(), datasetTable.getGroupKey());
        } else {
            if (opt_effect3D.isSelected()) {
                if (this.opt_effectStacked.isSelected())
                    ch.generate3DStackedBarChart(baseDataset);
                else
                    ch.generate3DBarChart(baseDataset);
            } else {
                if (this.opt_effectStacked.isSelected())
                    ch.generateStackedBarChart(baseDataset);
                else
                    ch.generateBarChart(baseDataset);
            }
        }
        //apply options
        if (this.opt_showGridline.isSelected()) {
            ch.setGridLineVisible(true);
        } else {
            ch.setGridLineVisible(false);
        }
        if (this.opt_showItemLabel.isSelected()) {
            ch.setItemLabelGenerator(txt_itemLabelFormat.getText(),
                    Integer.parseInt(cbo_itemLabelSize.getSelectedItem().toString()));
            ch.setItemLabelVisible(true);
        }
        c = ch;
        this.updateStatus("Bar chart has been generated.");
    } else if (this.combinedChartOption.isSelected()) {
        //not available yet
    } else {
        JOptionPane.showMessageDialog(this, "Please select chart type first!");
        return;
    }

    //c.generate3DStackedBarChart(baseDataset);
    ChartFrame f = c.drawChart("");
    panel = f.getChartPanel();
    splitPane.setDividerLocation(panel.getHeight());
    this.splitPane.setTopComponent(panel);
    //ChartPanel.add(panel);
    //panel.setSize(500, splitPane.getWidth());

    if (panel != null)
        panel.addHierarchyBoundsListener(new java.awt.event.HierarchyBoundsListener() {

            @Override
            public void ancestorResized(java.awt.event.HierarchyEvent evt) {
                panelAncestorResized(evt);
            };

            @Override
            public void ancestorMoved(HierarchyEvent e) {

            }
        });

    this.cmd_saveChart.setEnabled(true);
    this.cmd_changeSeriesColor.setEnabled(true);
    this.cmd_generateChart.setEnabled(false);

}