Example usage for org.jfree.chart ChartFactory createPieChart

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

Introduction

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

Prototype

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

Source Link

Document

Creates a pie chart with default settings.

Usage

From source file:net.sqs2.omr.result.export.chart.ChartImageWriter.java

public void savePieChart(OutputStream outputStream, DefaultPieDataset dataSet) {
    String title = "";

    boolean showLegend = true;
    boolean tooltips = true;
    boolean urls = false;

    JFreeChart chart = ChartFactory.createPieChart(title, dataSet, showLegend, tooltips, urls);
    PiePlot piePlot = (PiePlot) chart.getPlot();

    // chart.getLegend().setLegendItemGraphicEdge(RectangleEdge.RIGHT);
    // chart.getLegend().setLegendItemGraphicLocation(RectangleAnchor.RIGHT);
    chart.getLegend().setPosition(RectangleEdge.RIGHT);
    setSectionPaint(dataSet, piePlot);/*w  w  w . j av  a  2 s .  com*/

    try {
        ChartUtilities.writeChartAsPNG(outputStream, chart, this.width, this.height);
    } catch (IOException ioEx) {
        ioEx.printStackTrace();
    }
}

From source file:ch.unibe.iam.scg.archie.controller.ProviderChartFactory.java

/**
 * // w w w  . j a v  a 2 s .  c  om
 * @param pieDataset
 * @return
 */
private JFreeChart createJFreePieChart(PieDataset pieDataset) {
    if (this.model.isThreeDimensional()) {
        return ChartFactory.createPieChart3D(this.model.getChartName(), pieDataset, false, true, false);
    }
    return ChartFactory.createPieChart(this.model.getChartName(), pieDataset, false, true, false);
}

From source file:com.sun.portal.os.portlets.ChartServlet.java

private JFreeChart createChart(HttpServletRequest request) {
    JFreeChart chart = null;//ww  w.j a  va  2  s. c o m
    try {
        HttpSession session = request.getSession(true);
        PortletPreferences prefs = (PortletPreferences) session.getAttribute("PORTLET_PREFERENCES");

        if (prefs == null)
            throw new NoPreferredDbSetException("Preferences not passed in from portlet");

        String type = prefs.getValue(Constants.PREF_CHART_TYPE, PIE_CHART);

        debugMessage("Chart type :" + type);

        if (type.equals(PIE_CHART)) {
            String sql = prefs.getValue(Constants.PREF_PIE_CHART_SQL, DEFAULT_PIE_CHART_SQL);
            PieDataset data = (PieDataset) generatePieDataSet(getDatabaseConnection(request), sql);
            chart = ChartFactory.createPieChart("Pie Chart", data, true, true, false);
        } else if (type.equals(BAR_CHART)) {
            String sql = prefs.getValue(Constants.PREF_BAR_CHART_SQL, DEFAULT_BAR_CHART_SQL);
            JDBCCategoryDataset data = (JDBCCategoryDataset) generateBarChartDataSet(
                    getDatabaseConnection(request), sql);
            chart = ChartFactory.createBarChart3D("Bar Chart", "Category", "Value", data,
                    PlotOrientation.VERTICAL, true, true, false);
        } else if (type.equals(TIME_CHART)) {
            String sql = prefs.getValue(Constants.PREF_TIME_SERIES_SQL, DEFAULT_TIME_SERIES_SQL);
            JDBCXYDataset data = (JDBCXYDataset) generateXYDataSet(getDatabaseConnection(request), sql);
            chart = ChartFactory.createTimeSeriesChart("Time Series Chart", "Date", "Rate", data, true, true,
                    false);
        }

    } catch (NoPreferredDbSetException npdbs) {
        npdbs.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return chart;
}

From source file:org.apache.struts2.dispatcher.ChartResultTest.java

protected void setUp() throws Exception {
    super.setUp();

    DefaultPieDataset data = new DefaultPieDataset();
    data.setValue("Java", new Double(43.2));
    data.setValue("Visual Basic", new Double(0.0));
    data.setValue("C/C++", new Double(17.5));
    mockChart = ChartFactory.createPieChart("Pie Chart", data, true, true, false);

    stack = ActionContext.getContext().getValueStack();
    ActionContext.getContext().setValueStack(stack);

    mockActionProxy = EasyMock.createNiceMock(ActionProxy.class);
    EasyMock.expect(mockActionProxy.getNamespace()).andReturn("/html");

    actionInvocation = EasyMock.createMock(ActionInvocation.class);

    EasyMock.expect(actionInvocation.getStack()).andReturn(stack).anyTimes();

    os = new MockServletOutputStream();
    responseMock = EasyMock.createNiceMock(HttpServletResponse.class);

    ServletActionContext.setResponse((HttpServletResponse) responseMock);
}

From source file:userinterface.CountryNetworkAdminRole.CountryReportsJPanel.java

public JFreeChart createDonorsReportsChart(PieDataset dataSet, String chartTitle) {

    JFreeChart chart = ChartFactory.createPieChart(chartTitle, dataSet, true, true, false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setStartAngle(0);/*from   w  ww  .jav a  2 s .  com*/
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    return chart;
}

From source file:com.vectorprint.report.jfree.ChartBuilder.java

private void prepareChart(Dataset data, CHARTTYPE type) throws VectorPrintException {
    switch (type) {
    case AREA:/*  w ww  . j a v  a2s . c  om*/
        chart = ChartFactory.createAreaChart(title, categoryLabel, valueLabel, null, getOrientation(), legend,
                tooltips, urls);
    case LINE:
        if (chart == null) {
            chart = ChartFactory.createLineChart(title, categoryLabel, valueLabel, null, getOrientation(),
                    legend, tooltips, urls);
        }
    case LINE3D:
        if (chart == null) {
            chart = ChartFactory.createLineChart3D(title, categoryLabel, valueLabel, null, getOrientation(),
                    legend, tooltips, urls);
        }
    case BAR:
        if (chart == null) {
            chart = ChartFactory.createBarChart(title, categoryLabel, valueLabel, null, getOrientation(),
                    legend, tooltips, urls);
        }
    case BAR3D:
        if (chart == null) {
            chart = ChartFactory.createBarChart3D(title, categoryLabel, valueLabel, null, getOrientation(),
                    legend, tooltips, urls);
        }

        if (data instanceof CategoryDataset) {
            CategoryDataset cd = (CategoryDataset) data;

            chart.getCategoryPlot().setDataset(cd);
        } else {
            throw new VectorPrintException("you should use CategoryDataset for this chart");
        }

        break;

    case PIE:
        chart = ChartFactory.createPieChart(title, null, legend, tooltips, urls);
    case PIE3D:
        if (chart == null) {
            chart = ChartFactory.createPieChart3D(title, null, legend, tooltips, urls);
        }

        if (data instanceof PieDataset) {
            PieDataset pd = (PieDataset) data;
            PiePlot pp = (PiePlot) chart.getPlot();

            pp.setDataset(pd);
        } else {
            throw new VectorPrintException("you should use PieDataset for this chart");
        }

        break;

    case XYLINE:
        chart = ChartFactory.createXYLineChart(title, categoryLabel, valueLabel, null, getOrientation(), legend,
                tooltips, urls);
    case XYAREA:
        if (chart == null) {
            chart = ChartFactory.createXYAreaChart(title, categoryLabel, valueLabel, null, getOrientation(),
                    legend, tooltips, urls);
        }

        if (data instanceof XYDataset) {
            XYDataset xy = (XYDataset) data;

            chart.getXYPlot().setDataset(xy);
        } else {
            throw new VectorPrintException("you should use XYDataset for this chart");
        }

        break;

    case TIME:
        chart = ChartFactory.createTimeSeriesChart(title, categoryLabel, valueLabel, null, legend, tooltips,
                urls);

        if (data instanceof TimeSeriesCollection) {
            TimeSeriesCollection xy = (TimeSeriesCollection) data;

            chart.getXYPlot().setDataset(xy);
        } else {
            throw new VectorPrintException("you should use TimeSeriesCollection for this chart");
        }

        break;

    default:
        throw new VectorPrintException("unsupported chart");
    }

    chart.setAntiAlias(true);
    chart.setTextAntiAlias(true);
}

From source file:org.owasp.jbrofuzz.graph.canvas.StatusCodeChart.java

public ChartPanel getPlotCanvas() {

    final JFreeChart chart = ChartFactory.createPieChart("JBroFuzz Status Code Pie Chart", dataset, true, // legend?
            true, // tooltips?
            false // URLs?
    );//from w w w .j  a va  2s  . c o m

    final Plot plot = chart.getPlot();
    plot.setBackgroundImage(ImageCreator.IMG_OWASP_MED.getImage());
    plot.setBackgroundImageAlignment(Align.TOP_RIGHT);

    return new ChartPanel(chart);

}

From source file:ar.edu.uns.cs.vyglab.arq.rockar.gui.JFrameControlPanel.java

private void initCustomGUI() {
    // Crear un pie chart vacio
    pieChartDataset = new DefaultPieDataset();
    chart = ChartFactory.createPieChart("Rock.AR Pie Chart", // chart title
            pieChartDataset, // data
            false, // include legend
            true, false);/*from   w w  w  . j  a v  a  2s . c  om*/
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    jPanelPieChart = new ChartPanel(this.chart);
    jPanelTop.add(jPanelPieChart, BorderLayout.CENTER);
    // TODO
    // hacer que los colores del pie chart se correspondan con la tabla
}

From source file:treegross.standsimulation.TgGrafik.java

public JFreeChart createChart(Stand st) {
    // create the dataset...
    DefaultPieDataset dataset = new DefaultPieDataset();
    for (int j = 0; j < st.nspecies; j++) {
        dataset.setValue(st.sp[j].spDef.shortName, st.sp[j].percCSA);
    }//from  w  ww  . j av a2  s.  c  o  m
    //     
    JFreeChart chart = ChartFactory.createPieChart(messages.getString("speciespercentage"), // chart title
            dataset, // data
            true, // include legend
            true, // tooltips?
            false // URLs?
    );
    PiePlot piePlot = (PiePlot) chart.getPlot();
    for (int i = 0; i < st.nspecies; i++) {
        piePlot.setSectionPaint(i,
                new Color(st.sp[i].spDef.colorRed, st.sp[i].spDef.colorGreen, st.sp[i].spDef.colorBlue));
    }
    return chart;

}

From source file:uk.co.petertribble.solview.explorer.ArcStatPanel.java

/**
 * Craete a new ArcStatPanel, to display ZFS ARC statistics graphically.
 *
 * @param jkstat a JKstat object//w  ww . ja va2s .c om
 * @param interval the desired display update interval in seconds
 */
public ArcStatPanel(JKstat jkstat, int interval) {
    this.jkstat = jkstat;

    setDelay(interval);

    // FIXME all labels need to be localized

    // create a main panel
    setLayout(new SpringLayout());

    // initialise the datasets
    totalCacheHitsDataset = new DefaultPieDataset();
    currentCacheHitsDataset = new DefaultPieDataset();
    totalCacheHitsByTypeDataset = new DefaultPieDataset();
    currentCacheHitsByTypeDataset = new DefaultPieDataset();
    totalCacheMissesByTypeDataset = new DefaultPieDataset();
    currentCacheMissesByTypeDataset = new DefaultPieDataset();

    // initialise the pie charts
    // args: title, dataset, legend?, tooltips?, urls?
    JFreeChart totalCacheChart = ChartFactory.createPieChart("Total Cache Hits By List", totalCacheHitsDataset,
            false, true, false);
    JFreeChart currentCacheChart = ChartFactory.createPieChart("Current Cache Hits By List",
            currentCacheHitsDataset, false, true, false);
    JFreeChart totalCacheHitsByTypeChart = ChartFactory.createPieChart("Total Cache Hits By Type",
            totalCacheHitsByTypeDataset, false, true, false);
    JFreeChart currentCacheHitsByTypeChart = ChartFactory.createPieChart("Current Cache Hits By Type",
            currentCacheHitsByTypeDataset, false, true, false);
    JFreeChart totalCacheMissesByTypeChart = ChartFactory.createPieChart("Total Cache Misses By Type",
            totalCacheMissesByTypeDataset, false, true, false);
    JFreeChart currentCacheMissesByTypeChart = ChartFactory.createPieChart("Current Cache Misses By Type",
            currentCacheMissesByTypeDataset, false, true, false);

    /*
     * The overall layout is simple: at the top are the overall size
     * statistics. Then the percentages for hits/misses/types for the
     * cache are shown below.
     */
    JPanel infoPanel = new JPanel(new GridLayout(0, 2));
    JPanel hitPanel = new JPanel(new GridLayout(0, 2));
    JPanel cacheByListPanel = new JPanel(new GridLayout(1, 2));
    JPanel cacheHitByTypePanel = new JPanel(new GridLayout(1, 2));
    JPanel cacheMissByTypePanel = new JPanel(new GridLayout(1, 2));

    // cache hit rates, in a separate panel with bars.

    arc_hit_bar = new JProgressBar(0, 100);
    arc_hit_bar.setStringPainted(true);
    demand_hit_bar = new JProgressBar(0, 100);
    demand_hit_bar.setStringPainted(true);
    pf_hit_bar = new JProgressBar(0, 100);
    pf_hit_bar.setStringPainted(true);
    mdemand_hit_bar = new JProgressBar(0, 100);
    mdemand_hit_bar.setStringPainted(true);
    mpf_hit_bar = new JProgressBar(0, 100);
    mpf_hit_bar.setStringPainted(true);
    hitPanel.add(new JLabel("ARC hit rate"));
    hitPanel.add(arc_hit_bar);
    hitPanel.add(new JLabel("Demand data hit rate"));
    hitPanel.add(demand_hit_bar);
    hitPanel.add(new JLabel("Prefetch data hit rate"));
    hitPanel.add(pf_hit_bar);
    hitPanel.add(new JLabel("Demand metadata hit rate"));
    hitPanel.add(mdemand_hit_bar);
    hitPanel.add(new JLabel("Prefetch metadata hit rate"));
    hitPanel.add(mpf_hit_bar);
    hitPanel.setBorder(BorderFactory.createTitledBorder("Cache Hit Rates"));

    Dimension dchart = new Dimension(320, 240);
    ChartPanel cp1a = new ChartPanel(totalCacheChart);
    cp1a.setPreferredSize(dchart);
    ChartPanel cp1b = new ChartPanel(currentCacheChart);
    cp1b.setPreferredSize(dchart);
    ChartPanel cp2a = new ChartPanel(totalCacheHitsByTypeChart);
    cp2a.setPreferredSize(dchart);
    ChartPanel cp2b = new ChartPanel(currentCacheHitsByTypeChart);
    cp2b.setPreferredSize(dchart);
    ChartPanel cp3a = new ChartPanel(totalCacheMissesByTypeChart);
    cp3a.setPreferredSize(dchart);
    ChartPanel cp3b = new ChartPanel(currentCacheMissesByTypeChart);
    cp3b.setPreferredSize(dchart);

    infoPanel.add(new JLabel("Current size"));
    arc_size_label = new JLabel();
    infoPanel.add(arc_size_label);
    infoPanel.add(new JLabel("Target size"));
    target_size_label = new JLabel();
    infoPanel.add(target_size_label);
    infoPanel.add(new JLabel("Min size"));
    arc_min_size_label = new JLabel();
    infoPanel.add(arc_min_size_label);
    infoPanel.add(new JLabel("Max size"));
    arc_max_size_label = new JLabel();
    infoPanel.add(arc_max_size_label);
    infoPanel.add(new JLabel("MRU size"));
    mru_size_label = new JLabel();
    infoPanel.add(mru_size_label);
    infoPanel.add(new JLabel("MFU size"));
    mfu_size_label = new JLabel();
    infoPanel.add(mfu_size_label);
    infoPanel.setBorder(BorderFactory.createTitledBorder("Statistics"));

    cacheByListPanel.add(cp1a);
    cacheByListPanel.add(cp1b);
    cacheHitByTypePanel.add(cp2a);
    cacheHitByTypePanel.add(cp2b);
    cacheMissByTypePanel.add(cp3a);
    cacheMissByTypePanel.add(cp3b);

    add(infoPanel);
    add(hitPanel);
    add(cacheByListPanel);
    add(cacheHitByTypePanel);
    add(cacheMissByTypePanel);

    SpringUtilities.makeCompactGrid(this, 5, 1, 3, 3, 3, 3);

    update();
    startLoop();
}