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:org.jfree.chart.demo.PieChartDemo4.java

/**
 * Default constructor./*from  ww w  .j a  v  a 2s  .  co m*/
 *
 * @param title  the frame title.
 */
public PieChartDemo4(final String title) {

    super(title);
    final PieDataset dataset = createDataset(14);

    // create the chart...
    final JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 4", // chart title
            dataset, // dataset
            false, // include legend
            true, false);

    // set the background color for the chart...
    chart.setBackgroundPaint(new Color(222, 222, 255));
    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setCircular(true);
    plot.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data available");

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

    final Rotator rotator = new Rotator(plot);
    rotator.start();

}

From source file:org.gaixie.micrite.crm.action.CustomerChartAction.java

/**
 * 2D//from  ww w . j  a  va 2  s  .  c  o  m
 * @return "success"
 */
public String getPieChart() {
    PieDataset pd = customerService.getCustomerSourcePieDataset(this.getQueryBean());
    chart = ChartFactory.createPieChart(getText("customer.source.chart.pie.title"), pd, true, true, false);
    PieStyle.styleOne(chart);
    this.putChartResultList(chart);
    return SUCCESS;
}

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

/**
 * Default constructor.//ww w.  ja  va 2  s .c  om
 *
 * @param title  the frame title.
 */
public XMLPieChartDemo(final String title) {

    super(title);

    // create a dataset...
    PieDataset dataset = null;
    final URL url = getClass().getResource("/org/jfree/chart/demo/piedata.xml");

    try {
        final InputStream in = url.openStream();
        dataset = DatasetReader.readPieDatasetFromXML(in);
    } catch (IOException ioe) {
        System.out.println(ioe.getMessage());
    }

    // create the chart...
    final JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 1", // chart title
            dataset, // data
            true, // include legend
            true, false);

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.yellow);
    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data available");

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:fr.ensimag.biblio.controllers.StatImg.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request//from  w  w  w .j a  va2s .  c  o  m
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    OutputStream out = response.getOutputStream();
    response.setContentType("image/png");
    //int val1 = 40;
    //int val2 = 60;
    try {
        DefaultPieDataset dataset = new DefaultPieDataset();
        String title = "Statistiques";
        boolean legend = true;

        Map<String, String[]> params = request.getParameterMap();
        for (Map.Entry<String, String[]> param : params.entrySet()) {
            String key = param.getKey();
            String[] value = param.getValue();
            System.out.println("key : " + key + "value : " + value[0]);
            if (key.equals("legend"))
                legend = Boolean.parseBoolean(value[0]);
            else
                dataset.setValue(key, Double.parseDouble(value[0]));
        }

        //dataset.setValue("Valeur 1", val1);
        //dataset.setValue("Valeur 2", val2);
        JFreeChart chart = ChartFactory.createPieChart(title, dataset, legend, false, false);
        chart.setBackgroundPaint(Color.WHITE);
        ChartUtilities.writeChartAsPNG(out, chart, 500, 300);
    } finally {
        out.close();
    }
}

From source file:cn.edu.thss.iise.bpmdemo.charts.PieChartDemo4.java

/**
 * Default constructor./*from   w w  w. j a  v  a  2  s .co m*/
 *
 * @param title
 *            the frame title.
 */
public PieChartDemo4(final String title) {

    super(title);
    final PieDataset dataset = createDataset(14);

    // create the chart...
    final JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 4", // chart title
            dataset, // dataset
            false, // include legend
            true, false);

    // set the background color for the chart...
    chart.setBackgroundPaint(new Color(222, 222, 255));

    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setCircular(true);
    plot.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data available");

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

    // add table
    Object[][] data = { { "Kathy0", new Integer(0) }, { "Kathy1", new Integer(2) },
            { "Kathy2", new Integer(5) }, { "Kathy3", new Integer(5) }, { "Kathy4", new Integer(5) },
            { "Kathy5", new Integer(5) }, { "Kathy6", new Integer(5) }, { "Kathy7", new Integer(5) },
            { "Kathy8", new Integer(5) }, { "Kathy9", new Integer(5) } };
    String[] columnNames = { "Model Name", "Reuse Number" };
    JTable table = new JTable(data, columnNames);
    final JPanel panel = new JPanel();
    panel.add(chartPanel);
    panel.add(table);
    setContentPane(panel);
    final Rotator rotator = new Rotator(plot);
    rotator.start();

}

From source file:PieChartDemo1.java

/**
 * Creates a chart.//from ww w. j  av a 2s.  c  o  m
 *
 * @param dataset  the dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart("Smart Phones Manufactured / Q3 2011", // chart title
            dataset, // data
            false, // no legend
            true, // tooltips
            false // no URL generation
    );

    // set a custom background for the chart
    chart.setBackgroundPaint(
            new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY));

    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 26));

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.04);
    plot.setOutlineVisible(false);

    // use gradients and white borders for the section colours
    plot.setSectionPaint("Others", createGradientPaint(new Color(200, 200, 255), Color.BLUE));
    plot.setSectionPaint("Samsung", createGradientPaint(new Color(255, 200, 200), Color.RED));
    plot.setSectionPaint("Apple", createGradientPaint(new Color(200, 255, 200), Color.GREEN));
    plot.setSectionPaint("Nokia", createGradientPaint(new Color(200, 255, 200), Color.YELLOW));
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 20));
    plot.setLabelLinkPaint(Color.WHITE);
    plot.setLabelLinkStroke(new BasicStroke(2.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelBackgroundPaint(null);

    // add a subtitle giving the data source
    TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523",
            new Font("Courier New", Font.PLAIN, 12));
    source.setPaint(Color.WHITE);
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
    return chart;

}

From source file:dumbara.view.Chart1.java

public static void byAgent() {
    DefaultPieDataset objDataset = new DefaultPieDataset();
    try {/*from  w w w.  j  a v  a 2 s  . c  o  m*/
        Chart[] charts = SalesController.getAgencyAmounts();
        for (Chart chart : charts) {
            objDataset.setValue(chart.getAgencyID(), chart.getIncomeSum());
        }
    } catch (ClassNotFoundException | SQLException ex) {
        Logger.getLogger(Chart1.class.getName()).log(Level.SEVERE, null, ex);
    }
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MONTH, -1);
    Date result = cal.getTime();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("E yyyy.MM.dd");
    String format = simpleDateFormat.format(result);
    Date date = new Date();
    String format1 = simpleDateFormat.format(date);

    JFreeChart objChart = ChartFactory.createPieChart(
            "Sales Range of Agencies from " + format + " to " + format1, objDataset, true, true, false);
    ChartFrame frame = new ChartFrame("Data Analysis Wizard - v2.1.4", objChart);
    frame.pack();
    frame.setVisible(true);
    frame.setLocationRelativeTo(null);
}

From source file:com.thalesgroup.hudson.plugins.klocwork.graph.KloPieChart.java

protected JFreeChart createGraph() {

    JFreeChart chart = ChartFactory.createPieChart(null, dataset, true, true, false);
    chart.setBackgroundPaint(Color.white);

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setDataset(dataset);//www . j a v a  2 s  . c o  m
    plot.setOutlinePaint(null);
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No Klocwork data found.");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{1}"));

    // Set colours
    //plot.setOutlinePaint("New", new Color(200, 0, 0));
    int i = 0;
    if (kloConfig.getBuildGraph().isNeww() && kloReport.getNeww() > 0) {
        plot.setSectionPaint(plot.getDataset().getKey(i), new Color(200, 0, 0));
        i++;
    }
    if (kloConfig.getBuildGraph().isExisting() && kloReport.getExisting() > 0) {
        plot.setSectionPaint(plot.getDataset().getKey(i), new Color(0, 0, 200));
        i++;
    }
    if (kloConfig.getBuildGraph().isFixed() && kloReport.getFixed() > 0) {
        plot.setSectionPaint(plot.getDataset().getKey(i), new Color(0, 200, 0));
    }

    //plot.setOutlinePaint("Existing", new Color(0, 0, 200));
    //plot.setOutlinePaint("Fixed", new Color(0, 200, 0));

    return chart;

}

From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithPieChart.java

protected void init() {
    dataset = new DefaultPieDataset();
    JFreeChart chart = ChartFactory.createPieChart(null, dataset, true, true, false);

    init(chart.getPlot());/*from w  w  w  .  ja  va2 s  .  co  m*/
    //set font size to default
    setLabelFontSize(DEFAULT_LABEL_FONT_SIZE);
}

From source file:org.openmrs.module.vcttrac.web.view.chart.VCTCreatePieChartView.java

private JFreeChart createVCTvsPITPieChartView() {
    DefaultPieDataset pieDataset = new DefaultPieDataset();

    VCTModuleService service = Context.getService(VCTModuleService.class);

    try {//from   w w  w .  ja  v a 2 s . c o  m
        Date reportingDate = new Date();
        int numberOfClientInVCT = service.getNumberOfClientByVCTOrPIT(1, reportingDate);
        int numberOfClientInPIT = service.getNumberOfClientByVCTOrPIT(2, reportingDate);

        int all = numberOfClientInVCT + numberOfClientInPIT;

        Float percentageVCT = new Float(100 * numberOfClientInVCT / all);
        pieDataset.setValue(VCTTracUtil.getMessage("vcttrac.home.vctclient", null) + " (" + numberOfClientInVCT
                + " , " + percentageVCT + "%)", percentageVCT);

        Float percentagePIT = new Float(100 * numberOfClientInPIT / all);
        pieDataset.setValue(VCTTracUtil.getMessage("vcttrac.home.pitclient", null) + " (" + numberOfClientInPIT
                + " , " + percentagePIT + "%)", percentagePIT);

        JFreeChart chart = ChartFactory.createPieChart(
                VCTTracUtil.getMessage("vcttrac.home.vctclient", null) + " "
                        + VCTTracUtil.getMessage("vcttrac.graph.statistic.comparedto", null) + " "
                        + VCTTracUtil.getMessage("vcttrac.home.pitclient", null),
                pieDataset, true, true, false);

        return chart;
    } catch (Exception e) {
        log.error(">>VCT>>vs>>PIT>>PIE>>CHART>> " + e.getMessage());
        e.printStackTrace();
        return ChartFactory.createPieChart(VCTTracUtil.getMessage("vcttrac.home.vctclient", null) + " "
                + VCTTracUtil.getMessage("vcttrac.graph.statistic.comparedto", null) + " "
                + VCTTracUtil.getMessage("vcttrac.home.pitclient", null), null, true, true, false);
    }
}