Example usage for org.jfree.chart ChartFactory createMultiplePieChart

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

Introduction

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

Prototype

public static JFreeChart createMultiplePieChart(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:com.thecoderscorner.groovychart.chart.MultiplePieChart3D.java

public JFreeChart createChart() {
    return ChartFactory.createMultiplePieChart(getTitle(), (CategoryDataset) getDataset(), getOrder(),
            isLegend(), isTooltips(), isUrls());
}

From source file:com.thecoderscorner.groovychart.chart.MultiplePieChart.java

public JFreeChart createChart() {
    JFreeChart chart = ChartFactory.createMultiplePieChart(getTitle(), (CategoryDataset) getDataset(),
            getOrder(), isLegend(), isTooltips(), isUrls());
    return setExtraProperties(chart);

}

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 av  a2s. c om
    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:result.analysis.Chart.java

void perSemPerformace(String batch, String sem, String[] colleges) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (String college : colleges) {
        db = mongoClient.getDB(college);
        String collection_name = "cs_" + batch + "_" + sem + "_sem";
        DBCollection collection = db.getCollection(collection_name);

        analyz = new Analyze(db);
        double number = analyz.GetNumber(collection, "FAIL");
        dataset.setValue(number, college, "FAIL");
        number = analyz.GetNumber(collection, "FIRST CLASS");
        dataset.setValue(number, college, "First Class");

        number = analyz.GetNumber(collection, "SECOND CLASS");
        dataset.setValue(number, college, "Second class");

        number = analyz.GetNumber(collection, "FIRST CLASS WITH DISTINCTION");
        dataset.setValue(number, college, "First Class With Distinction");

    }/* w w  w  . j a  v a 2s.c  o m*/
    JFreeChart pieChart = ChartFactory.createMultiplePieChart("Classwise Distribution", dataset,
            TableOrder.BY_ROW, true, true, true);
    //        MultiplePiePlot plot = (MultiplePiePlot) pieChart.getPlot();
    //        plot.setStartAngle(290);
    //        plot.setDirection(Rotation.CLOCKWISE);
    //        plot.setForegroundAlpha(0.5f);
    MultiplePiePlot plot = (MultiplePiePlot) pieChart.getPlot();
    JFreeChart subchart = plot.getPieChart();
    PiePlot p = (PiePlot) subchart.getPlot();
    // p.setSimpleLabels(true);
    p.setExplodePercent("First Class With Distinction", 0.10);

    p.setExplodePercent("First Class", 0.10);
    p.setExplodePercent("Second class", 0.10);
    p.setExplodePercent("FAIL", 0.10);
    PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})",
            new DecimalFormat("0"), new DecimalFormat("0%"));
    p.setLabelGenerator(gen);

    ChartFrame frame = new ChartFrame("Semester Wise Performance of " + batch + " year", pieChart);
    frame.setVisible(true);
    frame.setSize(500, 500);
    save_jpeg(pieChart);

}

From source file:edu.gmu.cs.sim.util.media.chart.PieChartGenerator.java

protected void buildChart() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    chart = ChartFactory.createMultiplePieChart("Untitled Chart", dataset, org.jfree.util.TableOrder.BY_COLUMN,
            false, true, false);//from  w w w  . j  av  a 2 s .  c  o  m
    chart.setAntiAlias(true);
    //chartPanel = new ScrollableChartPanel(chart, true);            
    chartPanel = buildChartPanel(chart);
    //chartHolder.getViewport().setView(chartPanel);
    setChartPanel(chartPanel);

    JFreeChart baseChart = (JFreeChart) ((MultiplePiePlot) (chart.getPlot())).getPieChart();
    PiePlot base = (PiePlot) (baseChart.getPlot());
    base.setIgnoreZeroValues(true);
    base.setLabelOutlinePaint(java.awt.Color.WHITE);
    base.setLabelShadowPaint(java.awt.Color.WHITE);
    base.setMaximumLabelWidth(0.25); // allow bigger labels by a bit (this will make the chart smaller)
    base.setInteriorGap(0.000); // allow stretch to compensate for the bigger label width
    base.setLabelBackgroundPaint(java.awt.Color.WHITE);
    base.setOutlinePaint(null);
    base.setBackgroundPaint(null);
    base.setShadowPaint(null);
    base.setSimpleLabels(false); // I think they're false anyway

    // change the look of the series title to be smaller
    StandardChartTheme theme = new StandardChartTheme("Hi");
    TextTitle title = new TextTitle("Whatever", theme.getLargeFont());
    title.setPaint(theme.getAxisLabelPaint());
    title.setPosition(RectangleEdge.BOTTOM);
    baseChart.setTitle(title);

    // this must come last because the chart must exist for us to set its dataset
    setSeriesDataset(dataset);
}

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  w  w w .j a v a2s. co 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:com.twocents.test.ui.chart.MultipieChart.java

/**
 * Creates a sample chart with the given dataset.
 * // w w  w  .  jav  a2  s . com
 * @param dataset  the dataset.
 * 
 * @return A sample chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createMultiplePieChart("Multiple Pie Chart", // chart title
            dataset, // dataset
            TableOrder.BY_ROW, true, // include legend
            true, false);
    final MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();
    final JFreeChart subchart = plot.getPieChart();
    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.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  a 2  s.c  om*/
    } 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.MultiplePieChartDemo2.java

/**
 * Creates a sample chart with the given dataset.
 * /* w w w. j a va2  s  .  c  o  m*/
 * @param dataset  the dataset.
 * 
 * @return A sample chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createMultiplePieChart("Multiple Pie Chart", // chart title
            dataset, // dataset
            TableOrder.BY_COLUMN, true, // include legend
            true, false);
    final MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setOutlineStroke(new BasicStroke(1.0f));
    final JFreeChart subchart = plot.getPieChart();
    final PiePlot p = (PiePlot) subchart.getPlot();
    p.setBackgroundPaint(null);
    p.setOutlineStroke(null);
    p.setLabelGenerator(new StandardPieItemLabelGenerator("{0} ({2})", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    p.setMaximumLabelWidth(0.35);
    p.setLabelFont(new Font("SansSerif", Font.PLAIN, 9));
    p.setInteriorGap(0.30);
    return chart;
}

From source file:com.itemanalysis.jmetrik.graph.piechart.PieChartPanel.java

public void setGraph() {
    if (hasGroupVariable) {
        DefaultCategoryDataset piedat = new DefaultCategoryDataset();
        chart = ChartFactory.createMultiplePieChart(chartTitle, piedat, TableOrder.BY_ROW, showLegend, true,
                false);//w  w w  .j  a v  a2  s. c o  m

        if (chartSubtitle != null && !"".equals(chartSubtitle)) {
            TextTitle subtitle1 = new TextTitle(chartSubtitle);
            chart.addSubtitle(subtitle1);
        }

        MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();
        JFreeChart subchart = plot.getPieChart();
        PiePlot p = (PiePlot) subchart.getPlot();
        p.setBackgroundPaint(Color.WHITE);
        p.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})"));
        if (explode)
            p.setExplodePercent(explodeValue, explodePercent);

        ChartPanel panel = new ChartPanel(chart);
        panel.setPreferredSize(new Dimension(width, height));

        chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0));
        this.add(panel);
    } else {
        DefaultPieDataset piedat = new DefaultPieDataset();
        if (command.getSelectOneOption("view").isValueSelected("3D")) {
            chart = ChartFactory.createPieChart3D(chartTitle, piedat, showLegend, true, false);

            PiePlot3D plot = (PiePlot3D) chart.getPlot();
            plot.setStartAngle(290);
            plot.setDirection(Rotation.CLOCKWISE);
            plot.setForegroundAlpha(0.5f);
            plot.setNoDataMessage("No data to display");
            if (explode)
                plot.setExplodePercent(explodeValue, explodePercent);

        } else {
            chart = ChartFactory.createPieChart(command.getFreeOption("title").getString(), piedat, showLegend,
                    true, false);
        }

        if (chartSubtitle != null && !"".equals(chartSubtitle)) {
            TextTitle subtitle = new TextTitle(chartSubtitle);
            chart.addSubtitle(subtitle);
        }

        PiePlot plot = (PiePlot) chart.getPlot();
        plot.setLabelGap(0.02);
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})"));
        plot.setBackgroundPaint(Color.WHITE);
        if (explode)
            plot.setExplodePercent(explodeValue, explodePercent);

        ChartPanel panel = new ChartPanel(chart);
        panel.getPopupMenu().addSeparator();
        this.addJpgMenuItem(this, panel.getPopupMenu());
        panel.setPreferredSize(new Dimension(width, height));

        chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
        this.setBackground(Color.WHITE);
        this.add(panel);
    }

}