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:UserInterfaces.HAdministration.ReportDataJPanel.java

private void feedjButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_feedjButton2ActionPerformed
    // TODO add your handling code here:
    int satifynumber = 0;
    int unsatnumber = 0;

    //pop the last report
    //int workrequestSize = organization.getWorkQueue().getWorkRequestList().size();
    //WorkRequest lastRequest = organization.getWorkQueue().getWorkRequestList().get(workrequestSize - 1);
    for (WorkRequest workRequest : organization.getWorkQueue().getWorkRequestList()) {
        if (workRequest.getSatisfylevel().toString().equals(Reportsatifty.YES)) {
            satifynumber = satifynumber + 1;
        }//from  w  w  w.  jav a2s. c om
        if (workRequest.getSatisfylevel().toString().equals(Reportsatifty.NO)) {
            unsatnumber = unsatnumber + 1;
        }
    }

    ReportToReporter report = organization.getReport();
    report.setYes(satifynumber);
    report.setNo(unsatnumber);
    report.setStatus("success");

    DefaultPieDataset pieDataset = new DefaultPieDataset();
    pieDataset.setValue("satisfy", satifynumber);
    pieDataset.setValue("not satisfy", unsatnumber);
    JFreeChart chart = ChartFactory.createPieChart("Satifaction", pieDataset, true, true, true);

    PiePlot p = (PiePlot) chart.getPlot();
    // p.setForegroundAlpha(TOP_ALIGNMENT);

    ChartFrame frame = new ChartFrame("Chart for Satifaction", chart);
    frame.setVisible(true);
    frame.setSize(350, 450);

    //set the report to the enterprise`s report
    //so all the organization within the enterprise could get it
    for (Network network : es.getNetworkList()) {
        for (Enterprise e : network.getEd().getEnterprisesList()) {

            if (e.getOrgName().equals(enterprise.getOrgName())) {
                for (Enterprise en : network.getEd().getEnterprisesList()) {
                    if (en instanceof HospitalEnterprise || en instanceof ClinicEnterprise) {
                        en.setReport(report);
                        // System.out.println(en);
                    }

                }
            }

        }

    }

    //for (WorkRequest workRequest : organization.getWorkQueue().getWorkRequestList()) {

}

From source file:com.ikon.servlet.admin.StatsGraphServlet.java

/**
 * Generate memory statistics//from  ww w  .  ja  v a2  s  . co  m
 * http://blog.codebeach.com/2008/02/determine-available-memory-in-java.html
 */
public JFreeChart jvmMemStats() throws IOException, ServletException {
    Runtime runtime = Runtime.getRuntime();
    long max = runtime.maxMemory(); // maximum amount of memory that the JVM will attempt to use
    long available = runtime.totalMemory(); // total amount of memory in the JVM
    long free = runtime.freeMemory(); // amount of free memory in the JVM
    long used = max - available;
    long total = free + used;
    String title = "JVM memory: " + FormatUtil.formatSize(total);

    log.debug("JVM maximun memory: {}", FormatUtil.formatSize(max));
    log.debug("JVM available memory: {}", FormatUtil.formatSize(available));
    log.debug("JVM free memory: {}", FormatUtil.formatSize(free));
    log.debug("JVM used memory: {}", FormatUtil.formatSize(used));
    log.debug("JVM total memory: {}", FormatUtil.formatSize(total));

    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Available (" + FormatUtil.formatSize(free) + ")", free * 100 / total);
    dataset.setValue("Used (" + FormatUtil.formatSize(used) + ")", used * 100 / total);

    return ChartFactory.createPieChart(title, dataset, true, false, false);
}

From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java

/**
 * onClick button PieChart. <br>//from   w  ww .  j a  v  a  2s  .  c  o  m
 * 
 * @param event
 * @throws IOException
 */
public void onClick$button_CustomerChart_PieChart(Event event) throws InterruptedException, IOException {
    // logger.debug(event.toString());

    div_chartArea.getChildren().clear();

    // get the customer ID for which we want show a chart
    long kunId = getCustomer().getId();

    // get a list of data
    List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId);

    if (kunAmountList.size() > 0) {

        DefaultPieDataset pieDataset = new DefaultPieDataset();

        for (ChartData chartData : kunAmountList) {

            Calendar calendar = new GregorianCalendar();
            calendar.setTime(chartData.getChartKunInvoiceDate());

            int month = calendar.get(Calendar.MONTH) + 1;
            int year = calendar.get(Calendar.YEAR);
            String key = String.valueOf(month) + "/" + String.valueOf(year);

            BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3);
            String amount = String.valueOf(bd.doubleValue());

            // fill the data
            pieDataset.setValue(key + " " + amount,
                    new Double(chartData.getChartKunInvoiceAmount().doubleValue()));
        }

        String title = "Monthly amount for year 2009";
        JFreeChart chart = ChartFactory.createPieChart(title, pieDataset, true, true, true);
        PiePlot plot = (PiePlot) chart.getPlot();
        plot.setForegroundAlpha(0.5f);
        BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null);
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);

        AImage chartImage = new AImage("Pie Chart", bytes);

        Image img = new Image();
        img.setContent(chartImage);
        img.setParent(div_chartArea);

    } else {

        div_chartArea.getChildren().clear();

        Label label = new Label();
        label.setValue("This customer have no data for showing in a chart!");

        label.setParent(div_chartArea);

    }
}

From source file:vista.ReporteConversionLeads.java

public void iniciarGraficos(PieDataset datasetCantidades, PieDataset datasetConversion) {
    double porcConversion = 0;
    this.cantClientesLeadActuales.setText(Integer.toString(datasetCantidades.getValue(0).intValue()));
    this.cantClientesHabActuales.setText(Integer.toString(datasetCantidades.getValue(1).intValue()));
    double base = datasetConversion.getValue(0).floatValue() + datasetConversion.getValue(1).floatValue();
    if (base > 0) {
        porcConversion = (datasetConversion.getValue(1).floatValue() * 100) / base;
    }/*from w  w w . j av  a2 s .  com*/

    NumberFormat nf = new DecimalFormat("##.##");
    this.cantLeadsaHabituales.setText(nf.format(porcConversion) + "%");

    JFreeChart chartCa = ChartFactory.createPieChart("Clientes y Leads", // chart title 
            datasetCantidades, // data    
            true, // include legend   
            true, false);

    JFreeChart chartCo = ChartFactory.createPieChart("Conversion Leads a Habituales", // chart title 
            datasetConversion, // data    
            true, // include legend   
            true, false);

    ChartPanel chartCantidades = new ChartPanel(chartCa);
    ChartPanel chartConversion = new ChartPanel(chartCo);
    chartCantidades.setSize(new Dimension(600, 400));
    chartCantidades.setMouseWheelEnabled(true);
    chartConversion.setSize(new Dimension(600, 400));
    chartConversion.setMouseWheelEnabled(true);

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout
            .setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, 0)
                            .addComponent(chartCantidades).addContainerGap(0, Short.MAX_VALUE)));
    jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, 0).addComponent(chartCantidades)
                    .addContainerGap(0, Short.MAX_VALUE)));

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout
            .setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup().addGap(0, 0, 0)
                            .addComponent(chartConversion).addContainerGap(0, Short.MAX_VALUE)));
    jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup().addGap(0, 0, 0).addComponent(chartConversion)
                    .addContainerGap(0, Short.MAX_VALUE)));

}

From source file:ispd.gui.auxiliar.Graficos.java

public void criarComunicacao(Map<String, MetricasComunicacao> mComunicacao) {
    DefaultCategoryDataset dadosGraficoComunicacao = new DefaultCategoryDataset();
    DefaultPieDataset dadosGraficoPizzaComunicacao = new DefaultPieDataset();

    if (mComunicacao != null) {
        for (Map.Entry<String, MetricasComunicacao> entry : mComunicacao.entrySet()) {
            MetricasComunicacao link = entry.getValue();
            dadosGraficoComunicacao.addValue(link.getUnidadesTransmitidas(), "vermelho", link.getId());
            dadosGraficoPizzaComunicacao.insertValue(0, link.getId(), link.getUnidadesTransmitidas());
        }/* www .jav  a 2  s.com*/
    }

    JFreeChart jfc = ChartFactory.createBarChart("Total communication in each resource", //Titulo
            "Resource", // Eixo X
            "units", //Eixo Y
            dadosGraficoComunicacao, // Dados para o grafico
            PlotOrientation.VERTICAL, //Orientacao do grafico
            false, false, false); // exibir: legendas, tooltips, url
    //Inclina nome da barra em 45 graus
    if (mComunicacao != null && mComunicacao.size() > 10) {
        jfc.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    }
    CommunicationBarChart = new ChartPanel(jfc);
    CommunicationBarChart.setPreferredSize(new Dimension(600, 300));

    jfc = ChartFactory.createPieChart("Total communication in each resource", //Titulo
            dadosGraficoPizzaComunicacao, // Dados para o grafico
            true, false, false);
    CommunicationPieChart = new ChartPanel(jfc);
    CommunicationPieChart.setPreferredSize(new Dimension(600, 300));
}

From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java

/**
 * Generate a pie graph representing average build execution times across 
 * all builds in the list. /*w  w w  .  j  av  a  2s .  c o  m*/
 *
 * @param   builds  List of builds 
 * 
 * @return  Pie graph representing build execution times across all builds 
 */
public static final JFreeChart getAverageMetricChart(Vector<CMnDbBuildData> builds) {
    JFreeChart chart = null;

    // Get a list of all possible build metrics
    int[] metricTypes = CMnDbMetricData.getAllTypes();
    Hashtable metricAvg = new Hashtable(metricTypes.length);

    DefaultPieDataset dataset = new DefaultPieDataset();
    if ((builds != null) && (builds.size() > 0)) {

        // Collect build metrics for each of the builds in the list 
        Enumeration buildList = builds.elements();
        while (buildList.hasMoreElements()) {

            // Process the build metrics for the current build
            CMnDbBuildData build = (CMnDbBuildData) buildList.nextElement();
            Vector metrics = build.getMetrics();
            if ((metrics != null) && (metrics.size() > 0)) {
                // Collect data for each of the build metrics in the current build 
                Enumeration metricList = metrics.elements();
                while (metricList.hasMoreElements()) {
                    CMnDbMetricData currentMetric = (CMnDbMetricData) metricList.nextElement();
                    // Get elapsed time in "minutes"
                    Long elapsedTime = new Long(currentMetric.getElapsedTime() / (1000 * 60));
                    String metricName = CMnDbMetricData.getMetricType(currentMetric.getType());
                    Long avgValue = null;
                    if (metricAvg.containsKey(metricName)) {
                        Long oldAvg = (Long) metricAvg.get(metricName);
                        avgValue = oldAvg + elapsedTime;
                    } else {
                        avgValue = elapsedTime;
                    }
                    metricAvg.put(metricName, avgValue);

                } // while build has metrics

            } // if has metrics

        } // while list has elements

        // Populate the data set with the average values for each metric
        Enumeration keys = metricAvg.keys();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            Long total = (Long) metricAvg.get(key);
            Long avg = new Long(total.longValue() / (long) builds.size());
            //dataset.setValue(key, (Long) metricAvg.get(key));
            dataset.setValue(key, avg);
        }

    } // if list has elements

    // API: ChartFactory.createPieChart(title, data, legend, tooltips, urls)
    chart = ChartFactory.createPieChart("Average Build Metrics", dataset, true, true, false);

    // get a reference to the plot for further customization...
    PiePlot plot = (PiePlot) chart.getPlot();
    chartFormatter.formatMetricChart(plot, "min");

    return chart;
}

From source file:org.gephi.datalab.plugin.manipulators.columns.ColumnValuesFrequency.java

public JFreeChart buildPieChart(final Map<Object, Integer> valuesFrequencies) {
    final ArrayList<Object> values = new ArrayList<Object>(valuesFrequencies.keySet());
    DefaultPieDataset pieDataset = new DefaultPieDataset();

    for (Object value : values) {
        pieDataset.setValue(value != null ? "'" + value.toString() + "'" : "null",
                valuesFrequencies.get(value));
    }//from   w ww  .j a v  a 2 s .  c o m

    JFreeChart chart = ChartFactory.createPieChart(
            NbBundle.getMessage(ColumnValuesFrequency.class, "ColumnValuesFrequency.report.piechart.title"),
            pieDataset, false, true, false);
    return chart;
}

From source file:UserInterface.PatientRole.PatientReportChartJPanel.java

private void feedjButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_feedjButton2ActionPerformed
    // TODO add your handling code here:
    ReportToReporter report = enterprise.getReport();
    if (report.getStatus() != null) {
        DefaultPieDataset pieDataset = new DefaultPieDataset();
        pieDataset.setValue("satisfy", report.getYes());
        pieDataset.setValue("not satisfy", report.getNo());
        JFreeChart chart = ChartFactory.createPieChart("Satifaction", pieDataset, true, true, true);

        PiePlot p = (PiePlot) chart.getPlot();
        // p.setForegroundAlpha(TOP_ALIGNMENT);

        ChartFrame frame = new ChartFrame("Chart for Satifaction", chart);
        frame.setVisible(true);/*from   w  w  w.ja  va  2s.  co  m*/
        frame.setSize(350, 450);
    } else {
        JOptionPane.showMessageDialog(null, "Sorry, the final report has not been generated");
    }
}

From source file:UserInterface.CentreForDiseaseControl.DataAnalysis.java

private void salesDetailJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salesDetailJButtonActionPerformed
    // TODO add your handling code here:
    int totalVaccinesSold = 0;
    int totalQuantity = 0;
    VaccineManufacturerEnterprise popularManufacturer = null;
    DefaultPieDataset pieDataset = new DefaultPieDataset();

    for (VaccineManufacturerEnterprise manufactureres : enterprise.getVaccineManufacturerList()) {
        for (Order order : enterprise.getMasterOrderCatalog().getOrderList()) {
            for (OrderItem orderItem : order.getOrderItemList()) {
                if (orderItem.getVaccine().getVaccineManufacturer() == manufactureres) {
                    totalQuantity = totalQuantity + orderItem.getTotalQuantity();
                    if (totalQuantity > totalVaccinesSold) {
                        totalVaccinesSold = totalQuantity;
                        popularManufacturer = manufactureres;
                    }//  ww w.  j a  v  a 2s  .c  o m
                }
            }
        }
        pieDataset.setValue(manufactureres.getName(), totalQuantity);
        totalQuantity = 0;
    }

    JFreeChart chart = ChartFactory.createPieChart("Pie Chart", pieDataset, true, true, true);
    PiePlot p = (PiePlot) chart.getPlot();
    ChartFrame frame = new ChartFrame("Sale details of Manufacturers", chart);
    frame.setVisible(true);
    frame.setSize(450, 500);

}

From source file:edu.ku.brc.specify.plugins.ipadexporter.ChartHelper.java

/**
 * @param list//from   w ww . j  av a2 s .  co m
 * @param title
 * @param xAxisTitle
 * @param yAxisTitle
 * @param isVertical
 * @param width
 * @param height
 */
public JFreeChart createPieChart(final List<Object> list, final String title, final int width, final int height,
        final boolean do3D) {
    DefaultPieDataset dataset = new DefaultPieDataset();

    for (int i = 0; i < list.size(); i++) {
        Object descObj = list.get(i++);
        Object valObj = list.get(i);
        dataset.setValue(getString(descObj), getInt(valObj));
    }

    String adjTitle = title;
    JFreeChart chart = do3D ? ChartFactory.createPieChart3D(adjTitle, dataset, false, false, false)
            : ChartFactory.createPieChart(adjTitle, dataset, false, false, false);
    chart.setBackgroundPaint(new Color(0, 0, 0, 0)); // transparent black

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 11)); //$NON-NLS-1$
    plot.setBackgroundPaint(new Color(0, 0, 0, 0)); // transparent black
    plot.setOutlinePaint(null);

    setColors(plot, dataset);

    return chart;
}