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:feelings.analyser.views.MainView.java

/**
 * Creates new form MainView//from   w  w  w . ja  v  a  2s. c  om
 */

public MainView() {
    initComponents();
    init();

    dataChart.setValue("Positivo", 50);
    dataChart.setValue("Negativo", 50);

    JFreeChart chart = ChartFactory.createPieChart("Porcentaje", dataChart, true, true, false);

    ChartPanel chartPanel = new ChartPanel(chart);
    javax.swing.JButton button = new JButton("hola");
    jPanel2.add(chartPanel);

}

From source file:org.openmrs.module.usagestatistics668.web.view.chart.AccessVisitPieChartView.java

/**
 * create pie chart for visit data//from   www  .  j a v a 2  s .c  o m
 * @param model model built for view
 * @param request
 * @return JFREEChar pie chart
 */
@Override
protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) {
    AccessVisitService svc = Context.getService(AccessVisitService.class);

    List<Object[]> data = svc.getMostViewedVisit(getFromDate(), getUntilDate(), getUsageFilter(),
            getMaxResults());
    String[] categories = new String[data.size()];
    int[] count = new int[data.size()];
    for (int i = 0; i < categories.length; i++) {
        categories[i] = String.valueOf(data.get(i)[0]);
        count[i] = ((BigInteger) data.get(i)[1]).intValue();
    }

    String seriesView = ContextProvider.getMessage("usagestatistics668.summary.any");
    String title = "Most Accessed Visit Data";

    if (getUsageFilter() == ActionCriteria.CREATED) {
        seriesView = ContextProvider.getMessage("usagestatistics668.summary.created");
        title = "Most Created Visit Data";
    } else if (getUsageFilter() == ActionCriteria.UPDATED) {
        seriesView = ContextProvider.getMessage("usagestatistics668.summary.updated");
        title = "Most Updated Visit Data";
    } else if (getUsageFilter() == ActionCriteria.VIEWED) {
        seriesView = ContextProvider.getMessage("usagestatistics668.summary.viewed");
        title = "Most Vieweded Visit Data";
    } else if (getUsageFilter() == ActionCriteria.VOIDED) {
        seriesView = ContextProvider.getMessage("usagestatistics668.summary.voided");
        title = "Most Voided Visit Data";
    } else if (getUsageFilter() == ActionCriteria.UNVOIDED) {
        seriesView = ContextProvider.getMessage("usagestatistics668.summary.unvoided");
        title = "Most Unvoided Visit Data";
    }

    DefaultPieDataset dataset = new DefaultPieDataset();
    for (int c = 0; c < data.size(); c++) {
        dataset.setValue(String.valueOf(data.get(c)[0]), ((BigInteger) data.get(c)[1]).intValue());
    }

    JFreeChart chart = ChartFactory.createPieChart(title, // chart title
            dataset, // data
            false, // no legend
            true, // tooltips
            false // no URL generation
    );

    return chart;
}

From source file:cn.edu.thss.iise.bpmdemo.statistics.actions.ModelReusePanel.java

private JPanel createPanel() throws IOException {
    createDataSet();/* w  w  w .  j a v a  2  s .c o  m*/

    // create the chart...
    final JFreeChart chart = ChartFactory.createPieChart("Reused Times", // chart
            // title
            data1, // 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));

    String[] columnNames = { "Name", "Reuse Times" };
    JTable table = new JTable(data2, columnNames);
    JPanel panel = new JPanel();
    panel.add(chartPanel);
    panel.add(table);
    final Rotator rotator = new Rotator(plot);
    rotator.start();
    return panel;
}

From source file:org.openmrs.module.usagestatistics668.web.view.chart.AccessPatientPieChartView.java

/**
 * create pie chart for patient data/*  w w w.j  a  va2 s  . co  m*/
 * @param model model built for view
 * @param request
 * @return JFREEChar pie chart
 */
@Override
protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) {
    AccessPatientService svc = Context.getService(AccessPatientService.class);

    List<Object[]> data = svc.getMostViewedPatient(getFromDate(), getUntilDate(), getUsageFilter(),
            getMaxResults());

    String[] categories = new String[data.size()];
    int[] count = new int[data.size()];
    for (int i = 0; i < categories.length; i++) {
        categories[i] = String.valueOf(data.get(i)[0]);
        count[i] = ((BigInteger) data.get(i)[1]).intValue();
    }

    String seriesView = ContextProvider.getMessage("usagestatistics668.summary.any");
    String title = "Most Accessed Patient Data";

    if (getUsageFilter() == ActionCriteria.CREATED) {
        seriesView = ContextProvider.getMessage("usagestatistics668.summary.created");
        title = "Most Created Patient Data";
    } else if (getUsageFilter() == ActionCriteria.UPDATED) {
        seriesView = ContextProvider.getMessage("usagestatistics668.summary.updated");
        title = "Most Updated Patient Data";
    } else if (getUsageFilter() == ActionCriteria.VIEWED) {
        seriesView = ContextProvider.getMessage("usagestatistics668.summary.viewed");
        title = "Most Vieweded Patient Data";
    } else if (getUsageFilter() == ActionCriteria.VOIDED) {
        seriesView = ContextProvider.getMessage("usagestatistics668.summary.voided");
        title = "Most Voided Patient Data";
    } else if (getUsageFilter() == ActionCriteria.UNVOIDED) {
        seriesView = ContextProvider.getMessage("usagestatistics668.summary.unvoided");
        title = "Most Unvoided Patient Data";
    }

    DefaultPieDataset dataset = new DefaultPieDataset();
    for (int c = 0; c < data.size(); c++) {
        dataset.setValue(String.valueOf(data.get(c)[0]), ((BigInteger) data.get(c)[1]).intValue());
    }

    JFreeChart chart = ChartFactory.createPieChart(title, // chart title
            dataset, // data
            false, // no legend
            true, // tooltips
            false // no URL generation
    );

    return chart;
}

From source file:com.okmich.hackerday.client.tool.dashboard.ReportItemPanel.java

/**
 *
 * @return A panel.//from  w  w  w .  jav a  2s  . c  o  m
 */
public JPanel createChartPanel() {
    JFreeChart chart = ChartFactory.createPieChart(title, // chart title
            getChartDataset(), // data
            true, // include legend
            true, false);

    TextTitle textTitle = new TextTitle(title, new Font("SansSerif", Font.BOLD, 16));
    chart.setTitle(textTitle);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);

    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.BOTTOM);
    this.chartPanel = new ChartPanel(chart);
    this.chartPanel.addMouseListener(new MouseListenerImpl(this));

    return this.chartPanel;
}

From source file:org.openmrs.module.usagestatistics668.web.view.chart.AccessEncounterPieChartView.java

/**
 * create pie chart for encounter data/*from w  w  w.  j ava2  s. c o m*/
 * @param model model built for view
 * @param request
 * @return JFREEChar pie chart
 */
@Override
protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) {

    AccessEncounterService svc = Context.getService(AccessEncounterService.class);
    List<Object[]> data = svc.getMostViewedEncounter(getFromDate(), getUntilDate(), getUsageFilter(),
            getMaxResults());
    String[] categories = new String[data.size()];
    int[] count = new int[data.size()];
    for (int i = 0; i < categories.length; i++) {
        categories[i] = String.valueOf(data.get(i)[0]);
        count[i] = ((BigInteger) data.get(i)[1]).intValue();
    }

    String seriesView = ContextProvider.getMessage("usagestatistics668.summary.any");
    String title = "Most Accessed Encounter Data";

    if (getUsageFilter() == ActionCriteria.CREATED) {
        seriesView = ContextProvider.getMessage("usagestatistics668.summary.created");
        title = "Most Created Encounter Data";
    } else if (getUsageFilter() == ActionCriteria.UPDATED) {
        seriesView = ContextProvider.getMessage("usagestatistics668.summary.updated");
        title = "Most Updated Encounter Data";
    } else if (getUsageFilter() == ActionCriteria.VIEWED) {
        seriesView = ContextProvider.getMessage("usagestatistics668.summary.viewed");
        title = "Most Vieweded Encounter Data";
    } else if (getUsageFilter() == ActionCriteria.VOIDED) {
        seriesView = ContextProvider.getMessage("usagestatistics668.summary.voided");
        title = "Most Voided Encounter Data";
    } else if (getUsageFilter() == ActionCriteria.UNVOIDED) {
        seriesView = ContextProvider.getMessage("usagestatistics668.summary.unvoided");
        title = "Most Unvoided Encounter Data";
    }

    DefaultPieDataset dataset = new DefaultPieDataset();
    for (int c = 0; c < data.size(); c++) {
        dataset.setValue(String.valueOf(data.get(c)[0]), ((BigInteger) data.get(c)[1]).intValue());
    }

    JFreeChart chart = ChartFactory.createPieChart(title, // chart title
            dataset, // data
            false, // no legend
            true, // tooltips
            false // no URL generation
    );

    return chart;
}

From source file:edu.monash.merc.struts2.action.TLSumChartAction.java

@SuppressWarnings("unchecked")
public String piechart() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Green", l4);
    dataset.setValue("Yellow", l3);
    dataset.setValue("Red", l2);
    dataset.setValue("Black", l1);

    chart = ChartFactory.createPieChart(dt, dataset, true, true, false);
    PiePlot plot = (PiePlot) chart.getPlot();

    plot.setBackgroundPaint(Color.WHITE);
    //no border/*from w ww.ja  v a2s.  com*/
    plot.setOutlineStroke(null);
    //no label
    plot.setLabelGenerator(null);

    NumberFormat percentFormat = NumberFormat.getPercentInstance();
    percentFormat.setMaximumFractionDigits(2);
    plot.setLegendLabelGenerator(
            new StandardPieSectionLabelGenerator("{0}={2}", NumberFormat.getNumberInstance(), percentFormat));
    //set specific colors  green, yellow, red and black
    Color[] colors = { new Color(0, 140, 0), new Color(254, 172, 0), new Color(226, 0, 40),
            new Color(0, 0, 0) };
    setColor(plot, dataset, colors);

    chart.setBackgroundPaint(Color.WHITE);
    chart.getTitle().setFont(chart.getTitle().getFont().deriveFont(11.0f));
    return SUCCESS;
}

From source file:charts.PieChart3D.java

/**
 * Creates a chart.//from  w ww . j  a v  a2s.  co m
 *
 * @param dataset
 *            the dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset, PieChartModel model) {

    JFreeChart chart = ChartFactory.createPieChart(model.getTitle(), // 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("FCA", createGradientPaint(new Color(200, 200, 255), Color.BLUE));
    plot.setSectionPaint("FCH", createGradientPaint(new Color(255, 200, 200), Color.RED));
    plot.setSectionPaint("FCS", createGradientPaint(new Color(200, 255, 200), Color.GREEN));
    plot.setSectionPaint("FCG", createGradientPaint(new Color(200, 255, 200), Color.YELLOW));
    plot.setSectionPaint("FCJ", createGradientPaint(new Color(200, 255, 200), Color.BLACK));
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {1} ({2}) "));
    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(model.getSubTitle(), 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:org.openmrs.module.tracpatienttransfer.web.view.chart.OverviewOnExitPieChartView.java

@Override
protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) {

    JFreeChart chart = null;/*from w w  w  .ja v a 2 s .c  om*/
    UserContext userContext = Context.getUserContext();
    ApplicationContext appContext = ContextProvider.getApplicationContext();
    try {
        DefaultPieDataset pieDataset = new DefaultPieDataset();
        Concept reasonForExitCare = Context.getConceptService()
                .getConcept(TransferOutInPatientConstant.REASON_PATIENT_EXITED_FROM_CARE);
        Collection<ConceptAnswer> answers = reasonForExitCare.getAnswers();

        int total = Integer.valueOf(TransferOutInPatientTag.getNumberOfPatientExitedFromCare());

        int other = 0;
        Float percentage = 0f;
        for (ConceptAnswer ca : answers) {
            int nbrOfPatient = (Integer.valueOf(TransferOutInPatientTag
                    .getNumberOfPatientExitedFromCareWithReason(ca.getAnswerConcept().getConceptId())));
            percentage = (100f * nbrOfPatient / total);

            if (percentage > 5)
                pieDataset.setValue(
                        ca.getAnswerConcept().getDisplayString() + " (" + nbrOfPatient + " - "
                                + MohTracUtil.roundTo2DigitsAfterComma(percentage.doubleValue()) + "%)",
                        MohTracUtil.roundTo2DigitsAfterComma(percentage.doubleValue()));
            else
                other += nbrOfPatient;
        }

        if (other > 0) {
            String otherTitle = appContext.getMessage("tracpatienttransfer.others", null,
                    userContext.getLocale());
            percentage = (100f * other / total);
            pieDataset.setValue(
                    otherTitle + " (" + other + " - "
                            + MohTracUtil.roundTo2DigitsAfterComma(percentage.doubleValue()) + "%)",
                    MohTracUtil.roundTo2DigitsAfterComma(percentage.doubleValue()));
        }
        chart = ChartFactory.createPieChart(reasonForExitCare.getDisplayString(), pieDataset, true, true,
                false);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return chart;
}

From source file:com.church.tools.ChartTools.java

/**
 * Generate pie chart.//from  w  w  w. j  ava2s .  c om
 * 
 * @param title the title
 * @param values the values
 * @param captions the captions
 * @param width the width
 * @param height the height
 * @param color the color
 * 
 * @return the buffered image
 */
public static BufferedImage GeneratePieChart(String title, double[] values, String[] captions, int width,
        int height, Color color) {
    BufferedImage bufferedImage = null;
    DefaultPieDataset pieDataset = new DefaultPieDataset();
    Hashtable<String, String> ht = new Hashtable<String, String>();
    for (int i = 0; i < values.length; i++)
        ht.put(captions[i], Double.toString(values[i]));

    Enumeration<String> enu = ht.keys();
    int i = 0;
    while (enu.hasMoreElements()) {
        String str = (String) enu.nextElement();
        pieDataset.setValue(str, new Double(Double.parseDouble((String) ht.get(str))));
        i++;
    }

    JFreeChart chart = ChartFactory.createPieChart(title, pieDataset, false, false, false);
    chart.setBackgroundPaint(color);
    bufferedImage = chart.createBufferedImage(width, height);
    return bufferedImage;
}