Example usage for org.jfree.chart ChartFactory createMultiplePieChart3D

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

Introduction

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

Prototype

public static JFreeChart createMultiplePieChart3D(String title, CategoryDataset dataset, TableOrder order,
        boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates a chart that displays multiple pie plots.

Usage

From source file:org.operamasks.faces.render.graph.PieChartRenderer.java

protected JFreeChart createChart(UIChart comp) {
    Dataset dataset = createDataset(comp);
    JFreeChart chart = null;/*from   w w w .j ava  2s.  co m*/
    PiePlot pieplot = null;

    boolean ring = Coercion.coerceToBoolean(comp.getAttributes().get("ring"));

    if (dataset instanceof CategoryDataset) {
        CategoryDataset catset = (CategoryDataset) dataset;

        if (catset.getRowCount() == 1) {
            PieDataset pieset = new CategoryToPieDataset(catset, TableOrder.BY_ROW, 0);

            if (ring) {
                chart = ChartFactory.createRingChart(null, pieset, false, false, false);
            } else if (comp.isEffect3D()) {
                chart = ChartFactory.createPieChart3D(null, pieset, false, false, false);
            } else {
                chart = ChartFactory.createPieChart(null, pieset, false, false, false);
            }

            pieplot = (PiePlot) chart.getPlot();
        } else {
            if (comp.isEffect3D()) {
                chart = ChartFactory.createMultiplePieChart3D(null, catset, TableOrder.BY_ROW, false, false,
                        false);
            } else {
                chart = ChartFactory.createMultiplePieChart(null, catset, TableOrder.BY_ROW, false, false,
                        false);
            }

            pieplot = (PiePlot) ((MultiplePiePlot) chart.getPlot()).getPieChart().getPlot();
        }
    }

    if (pieplot != null) {
        if (!comp.isDrawItemLabel()) {
            pieplot.setLabelGenerator(null);
        }

        if (comp.isShowItemTips()) {
            pieplot.setToolTipGenerator(new StandardPieToolTipGenerator());
        }

        Object startAngle = comp.getAttributes().get("startAngle");
        if (startAngle != null) {
            pieplot.setStartAngle(Coercion.coerceToDouble(startAngle));
        }
    }

    return chart;
}

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;//from  www  . ja va2  s. c  o  m
    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:org.pentaho.plugin.jfreereport.reportcharts.MultiPieChartExpression.java

protected JFreeChart computeChart(final Dataset dataset) {
    final CategoryDataset categoryDataset;
    if (dataset instanceof CategoryDataset == false) {
        categoryDataset = null;/*from  w  ww  .  j  a  v  a2  s  . c o  m*/
    } else {
        categoryDataset = (CategoryDataset) dataset;
    }

    final TableOrder order;
    if (isMultipieByRow()) {
        order = TableOrder.BY_ROW;
    } else {
        order = TableOrder.BY_COLUMN;
    }

    if (isThreeD()) {
        return ChartFactory.createMultiplePieChart3D(computeTitle(), categoryDataset, order, isShowLegend(),
                false, false);
    } else {
        return ChartFactory.createMultiplePieChart(computeTitle(), categoryDataset, order, isShowLegend(),
                false, false);
    }
}

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

/**
 * Creates a sample chart for the given dataset.
 * //from   w w w .  j  a  v  a  2  s  .  co  m
 * @param dataset  the dataset.
 * 
 * @return A sample chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createMultiplePieChart3D("Multiple Pie Chart Demo 3", dataset,
            TableOrder.BY_COLUMN, true, true, false);
    chart.setBackgroundPaint(new Color(216, 255, 216));
    final MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();
    final PiePlot p = (PiePlot) plot.getPieChart().getPlot();
    p.setMaximumLabelWidth(0.35);
    p.setLabelFont(new Font("SansSerif", Font.PLAIN, 9));
    p.setInteriorGap(0.30);
    return chart;
}

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

/**
 * Creates a sample chart for the given dataset.
 * /*from w  w w  . j  a  va 2s.  c  om*/
 * @param dataset  the dataset.
 * 
 * @return A sample chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createMultiplePieChart3D("Multiple Pie Chart Demo 4", dataset,
            TableOrder.BY_COLUMN, false, true, false);
    chart.setBackgroundPaint(new Color(216, 255, 216));
    final MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();
    final JFreeChart subchart = plot.getPieChart();
    //        final StandardLegend legend = new StandardLegend();
    //      legend.setItemFont(new Font("SansSerif", Font.PLAIN, 8));
    //    legend.setAnchor(Legend.SOUTH);
    //  subchart.setLegend(legend);
    plot.setLimit(0.10);
    final PiePlot p = (PiePlot) subchart.getPlot();
    p.setLabelGenerator(new StandardPieItemLabelGenerator("{0}"));
    p.setLabelFont(new Font("SansSerif", Font.PLAIN, 8));
    p.setInteriorGap(0.30);

    return chart;
}

From source file:org.exist.xquery.modules.jfreechart.JFreeChartFactory.java

/**
 *  Create JFreeChart graph using the supplied parameters.
 *
 * @param chartType One of the many chart types.
 * @param conf      Chart configuration//w w w  . ja  va  2s  .c  o  m
 * @param is        Inputstream containing chart data
 * @return          Initialized chart or NULL in case of issues.
 * @throws IOException Thrown when a problem is reported while parsing XML data.
 */
public static JFreeChart createJFreeChart(String chartType, Configuration conf, InputStream is)
        throws XPathException {

    logger.debug("Generating " + chartType);

    // Currently two dataset types supported
    CategoryDataset categoryDataset = null;
    PieDataset pieDataset = null;

    try {
        if ("PieChart".equals(chartType) || "PieChart3D".equals(chartType) || "RingChart".equals(chartType)) {
            logger.debug("Reading XML PieDataset");
            pieDataset = DatasetReader.readPieDatasetFromXML(is);

        } else {
            logger.debug("Reading XML CategoryDataset");
            categoryDataset = DatasetReader.readCategoryDatasetFromXML(is);
        }

    } catch (IOException ex) {
        throw new XPathException(ex.getMessage());

    } finally {
        try {
            is.close();
        } catch (IOException ex) {
            //
        }
    }

    // Return chart
    JFreeChart chart = null;

    // Big chart type switch
    if ("AreaChart".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createAreaChart(conf.getTitle(), conf.getCategoryAxisLabel(),
                conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setCategoryChartParameters(chart, conf);

    } else if ("BarChart".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createBarChart(conf.getTitle(), conf.getCategoryAxisLabel(),
                conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setCategoryChartParameters(chart, conf);

    } else if ("BarChart3D".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createBarChart3D(conf.getTitle(), conf.getCategoryAxisLabel(),
                conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setCategoryChartParameters(chart, conf);

    } else if ("LineChart".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createLineChart(conf.getTitle(), conf.getCategoryAxisLabel(),
                conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setCategoryChartParameters(chart, conf);

    } else if ("LineChart3D".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createLineChart3D(conf.getTitle(), conf.getCategoryAxisLabel(),
                conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setCategoryChartParameters(chart, conf);

    } else if ("MultiplePieChart".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createMultiplePieChart(conf.getTitle(), categoryDataset, conf.getOrder(),
                conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls());

        setPieChartParameters(chart, conf);

    } else if ("MultiplePieChart3D".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createMultiplePieChart3D(conf.getTitle(), categoryDataset, conf.getOrder(),
                conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls());

        setPieChartParameters(chart, conf);

    } else if ("PieChart".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createPieChart(conf.getTitle(), pieDataset, conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setPieChartParameters(chart, conf);

    } else if ("PieChart3D".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createPieChart3D(conf.getTitle(), pieDataset, conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setPieChartParameters(chart, conf);

    } else if ("RingChart".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createRingChart(conf.getTitle(), pieDataset, conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setPieChartParameters(chart, conf);
    } else if ("SpiderWebChart".equalsIgnoreCase(chartType)) {
        SpiderWebPlot plot = new SpiderWebPlot(categoryDataset);
        if (conf.isGenerateTooltips()) {
            plot.setToolTipGenerator(new StandardCategoryToolTipGenerator());
        }
        chart = new JFreeChart(conf.getTitle(), JFreeChart.DEFAULT_TITLE_FONT, plot, false);

        if (conf.isGenerateLegend()) {
            LegendTitle legend = new LegendTitle(plot);
            legend.setPosition(RectangleEdge.BOTTOM);
            chart.addSubtitle(legend);
        } else {
            TextTitle subTitle = new TextTitle(" ");
            subTitle.setPosition(RectangleEdge.BOTTOM);
            chart.addSubtitle(subTitle);
        }

        setCategoryChartParameters(chart, conf);

    } else if ("StackedAreaChart".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createStackedAreaChart(conf.getTitle(), conf.getCategoryAxisLabel(),
                conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setCategoryChartParameters(chart, conf);

    } else if ("StackedBarChart".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createStackedBarChart(conf.getTitle(), conf.getDomainAxisLabel(),
                conf.getRangeAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setCategoryChartParameters(chart, conf);

    } else if ("StackedBarChart3D".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createStackedBarChart3D(conf.getTitle(), conf.getCategoryAxisLabel(),
                conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setCategoryChartParameters(chart, conf);

    } else if ("WaterfallChart".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createWaterfallChart(conf.getTitle(), conf.getCategoryAxisLabel(),
                conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setCategoryChartParameters(chart, conf);
    } else {
        logger.error("Illegal chartype. Choose one of " + "AreaChart BarChart BarChart3D LineChart LineChart3D "
                + "MultiplePieChart MultiplePieChart3D PieChart PieChart3D "
                + "RingChart SpiderWebChart StackedAreaChart StackedBarChart "
                + "StackedBarChart3D WaterfallChart");
    }

    setCommonParameters(chart, conf);

    return chart;
}

From source file:edu.uara.wrappers.customcharts.CustomPieChart.java

@Override
public void generateMultiple3DPieChart(CategoryDataset dataset, TableOrder order) {
    ds = dataset;//store dataset for update
    try {/*w ww . j a v a 2 s .co  m*/
        currentDatasetType = DatasetTypes.CategoryDataset;
        if (dataset == null)
            throw new Exception("No dataset provided");
        chart = ChartFactory.createMultiplePieChart3D(title, dataset, order, legend, // legend?
                false, // no tooltip needed
                false // mo URL needed
        );
        currentDatasetType = DatasetTypes.PieDataset;
    } catch (Exception ex) {
        //handle exception
        System.out.print("Error Generating 3D muliple pie chart. " + ex.getMessage());
    }
}

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

private static JFreeChart createMultiplePieChart3D(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createMultiplePieChart3D("MultiplePie Chart 3D Demo 1", // chart title
            dataset, // data
            TableOrder.BY_COLUMN, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*w  ww  . j  av a2s.  co  m*/

    chart.setBackgroundPaint(Color.white);

    MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();
    JFreeChart pieChart = plot.getPieChart();
    PiePlot piePlot = (PiePlot) pieChart.getPlot();

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    piePlot.setSectionPaint("First", gp0);
    piePlot.setSectionPaint("Second", gp1);
    piePlot.setSectionPaint("Third", gp2);

    return chart;

}

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

private static JFreeChart createMultiplePieChart3D_2(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createMultiplePieChart3D("MultiplePie Chart 3D Demo 2", // chart title
            dataset, // data
            TableOrder.BY_ROW, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from   ww w .j av  a  2s.co  m*/

    chart.setBackgroundPaint(Color.white);

    return chart;

}

From source file:NewGUI.Statistics.java

public void setChart(Boolean isChartBar) {

    SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    String sql = "";
    String title1 = "", title2 = "", title3 = "";
    String s1, s2, s3, s4;//from   w ww  .java2 s .  co m
    if (cboxType.getSelectedIndex() == 0) {
        s1 = "importing";
        s2 = "import_type_id";
        s3 = "thu nhp";
        s4 = "import_type";

    } else {
        s1 = "exporting";
        s2 = "export_type_id";
        s3 = "chi tiu";
        s4 = "export_type";
    }
    int caseSQL = 4 * (checkBoxCategory.isSelected() ? 1 : 0) + 2 * (checkBoxMonth.isSelected() ? 1 : 0)
            + (checkBoxYear.isSelected() ? 1 : 0);

    int year = jycFrom.getValue();
    int month = cboxMonth.getSelectedIndex();
    DefaultCategoryDataset categoryDataset = new DefaultCategoryDataset();
    DefaultPieDataset pieDataset = new DefaultPieDataset();
    ArrayList<Integer> listAccount = filter.getListAcount();

    for (int i = 0; i < listAccount.size(); i++) {
        String sql1 = "select x.user_id,user.userName,y.name,x.value,x.date from "
                + "(select a.id,a.user_id,a.value,a.date,a.category_id from " + "(select * from "
                + (cboxType.getSelectedIndex() == 0 ? "importing" : "exporting") + " where date between '"
                + df.format(jdcFrom.getDate()).toString() + "' and '" + df.format(jdcTo.getDate()).toString()
                + "' and user_id in(" + getAccountList() + ") " + getStringAmount() + " " + getStringText()
                + " " + getStringCategory() + ") as a," + "(select * from share where user_id = 1 and type_id="
                + (cboxType.getSelectedIndex() == 0 ? 1 : 2) + ")as b where b.transaction_id=a.id)as x,"
                + "user,import_type as y where x.user_id = user.id and x.category_id=y.id";

        sql1 = "(" + sql1 + ")as x";

        switch (caseSQL) {
        case 0:
            sql = "select sum(value),year(date),userName from " + sql1 + " where user_id=" + listAccount.get(i)
                    + " group by(year(date))";
            title1 = "";
            title2 = "Bng thng k " + s3 + " cc nm";
            title3 = "";
            break;
        case 1:
            sql = "select sum(value),month(date),userName from " + sql1 + " where user_id=" + listAccount.get(i)
                    + " and year(date)=" + year + " group by (month(date))";
            title1 = "T.";
            title2 = "Bng thng k " + s3 + " trong nm " + year;
            title3 = "";
            break;
        case 2:
            sql = "select sum(value),year(date),userName from " + sql1 + " where user_id=" + listAccount.get(i)
                    + " and month(date)=" + month + " group by (year(date))";
            title1 = "";
            title2 = "Bng thng k " + s3 + " thng " + month + " trong cc nm";
            title3 = "";
            break;
        case 3:
            sql = "select sum(value),name,userName from " + sql1 + " where user_id=" + listAccount.get(i)
                    + " and month(date)=" + month + " and year(date)=" + year + " group by name";
            title1 = "";
            title2 = "Bng thng k " + s3 + " thng " + month + " trong nm " + year;
            title3 = "";
            break;
        case 4:
            sql = "select sum(value),year(date),userName from " + sql1 + " where user_id=" + listAccount.get(i)
                    + " group by (year(date))";
            title1 = "";
            title2 = "Bng thng k " + s3 + " '" + "' trong cc nm";
            title3 = "";
            break;
        case 5:
            sql = "select sum(value),month(date),userName from " + sql1 + "where user_id=" + listAccount.get(i)
                    + " and year(date)=" + year + " group by (month(date))";
            title1 = "T.";
            title2 = "Bng thng k " + s3 + " '" + "' trong nm " + year;
            title3 = "";
            break;
        case 6:
            sql = "select sum(value),year(date),userName from " + sql1 + " where user_id=" + listAccount.get(i)
                    + " and month(date)=" + month + " group by (year(date))";
            title1 = "";
            title2 = "Bng thng k " + s3 + " '" + "' thng " + month + " trong cc nm";
            title3 = "";
            break;
        case 7:
            sql = "select sum(value),year(date),userName from " + sql1 + " where user_id=" + listAccount.get(i)
                    + " and month(date)=" + month + " and year(date)=" + year;
            title1 = "";
            title2 = "Bng thng k " + s3 + " '" + "' thng " + month + " trong nm " + year;
            title3 = "";
            break;
        }
        System.out.println(sql);
        try {
            ResultSet rs = Database.stm.executeQuery(sql);

            while (rs.next()) {
                categoryDataset.setValue(rs.getInt(1), rs.getString(3), title1 + rs.getString(2));
            }

        } catch (Exception ex) {
            System.out.println("Loi...");
        }

    }

    if (isChartBar) {
        chart = ChartFactory.createBarChart3D("", title2, title3, categoryDataset, PlotOrientation.VERTICAL,
                true, true, false);
    } else {
        chart = ChartFactory.createMultiplePieChart3D(title2, categoryDataset, TableOrder.BY_COLUMN, true, true,
                true);
    }
    chartPanel.setChart(chart);
    jtabpanelView.setSelectedIndex(1);
}