Example usage for org.jfree.data.general DefaultPieDataset setValue

List of usage examples for org.jfree.data.general DefaultPieDataset setValue

Introduction

In this page you can find the example usage for org.jfree.data.general DefaultPieDataset setValue.

Prototype

public void setValue(Comparable key, double value) 

Source Link

Document

Sets the data value for a key and sends a DatasetChangeEvent to all registered listeners.

Usage

From source file:HW3.java

private void displayPiechartButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_displayPiechartButtonActionPerformed
    // TODO add your handling code here:
    DefaultPieDataset pieDataset = new DefaultPieDataset();
    int val[] = new int[5];
    piechartValues(val);
    if (val[0] > 0) {
        pieDataset.setValue("1 Star=" + val[0], new Integer(val[0]));
    }//from w  w  w . j  a  v a2s  .  c  o m
    if (val[1] > 0) {
        pieDataset.setValue("2 Star=" + val[1], new Integer(val[1]));
    }
    if (val[2] > 0) {
        pieDataset.setValue("3 Star=" + val[2], new Integer(val[2]));
    }
    if (val[3] > 0) {
        pieDataset.setValue("4 Star=" + val[3], new Integer(val[3]));
    }
    if (val[4] > 0) {
        pieDataset.setValue("5 Star=" + val[4], new Integer(val[4]));
    }
    int total = val[0] + val[1] + val[2] + val[3] + val[4];
    JFreeChart chart = ChartFactory.createPieChart("Piechart\n Total Reviews : " + total, pieDataset, true,
            true, true);
    PiePlot P = (PiePlot) chart.getPlot();
    ChartFrame frame = new ChartFrame("Pie Chart", chart);
    frame.setVisible(true);
    frame.setSize(500, 500);
}

From source file:org.jajuk.ui.views.StatView.java

/**
 * Device size pie./*from   ww w  . j  av  a 2s  .c o  m*/
 * 
 * @return the chart
 */
private ChartPanel createDeviceRepartition() {
    try {
        DefaultPieDataset pdata = null;
        JFreeChart jfchart = null;
        // data
        pdata = new DefaultPieDataset();
        // prepare devices
        long lTotalSize = 0;
        double dOthers = 0;
        List<Device> devices = DeviceManager.getInstance().getDevices();
        long[] lSizes = new long[DeviceManager.getInstance().getElementCount()];
        ReadOnlyIterator<File> it = FileManager.getInstance().getFilesIterator();
        while (it.hasNext()) {
            File file = it.next();
            lTotalSize += file.getSize();
            lSizes[devices.indexOf(file.getDirectory().getDevice())] += file.getSize();
        }
        for (Device device : devices) {
            long lSize = lSizes[devices.indexOf(device)];
            if (lTotalSize > 0 && (double) lSize / lTotalSize < 0.05) {
                // less than 5% -> go to others
                dOthers += lSize;
            } else {
                double dValue = Math.round((double) lSize / 1073741824);
                pdata.setValue(device.getName(), dValue);
            }
        }
        if (dOthers > 0) {
            double dValue = Math.round((dOthers / 1073741824));
            pdata.setValue(Messages.getString("StatView.3"), dValue);
        }
        // chart
        jfchart = ChartFactory.createPieChart3D(Messages.getString("StatView.4"), pdata, true, true, true);
        // set the background color for the chart...
        PiePlot plot = (PiePlot) jfchart.getPlot();
        plot.setLabelFont(PiePlot.DEFAULT_LABEL_FONT);
        plot.setNoDataMessage(Messages.getString("StatView.5"));
        plot.setForegroundAlpha(0.5f);
        plot.setBackgroundAlpha(0.5f);
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1} GB ({2})"));
        plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} = {1} GB ({2})"));
        return new ChartPanel(jfchart);
    } catch (RuntimeException e) {
        Log.error(e);
        return null;
    }
}

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

/**
 * Generate a pie graph representing test counts for each product area. 
 *
 * @param   suites   List of test suites
 * @param   areas    List of product areas 
 * /*ww  w  .j av  a2 s  .  c o m*/
 * @return  Pie graph representing build execution times across all builds 
 */
public static final JFreeChart getAverageAreaTestTimeChart(Vector<CMnDbBuildData> builds,
        Vector<CMnDbTestSuite> suites, Vector<CMnDbFeatureOwnerData> areas) {
    JFreeChart chart = null;

    // Collect the average of all test types 
    Hashtable timeAvg = new Hashtable();

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

        // Collect test data for each of the suites in the list 
        Enumeration suiteList = suites.elements();
        while (suiteList.hasMoreElements()) {

            // Process the data for the current suite
            CMnDbTestSuite suite = (CMnDbTestSuite) suiteList.nextElement();
            Long elapsedTime = new Long(suite.getElapsedTime() / (1000 * 60));
            CMnDbFeatureOwnerData area = null;

            // Iterate through each product area to determine who owns this suite
            CMnDbFeatureOwnerData currentArea = null;
            Iterator iter = areas.iterator();
            while (iter.hasNext()) {
                currentArea = (CMnDbFeatureOwnerData) iter.next();
                if (currentArea.hasFeature(suite.getGroupName())) {
                    Long avgValue = null;
                    String areaName = currentArea.getDisplayName();
                    if (timeAvg.containsKey(areaName)) {
                        Long oldAvg = (Long) timeAvg.get(areaName);
                        avgValue = oldAvg + elapsedTime;
                    } else {
                        avgValue = elapsedTime;
                    }
                    timeAvg.put(areaName, avgValue);

                }
            }

        } // while list has elements

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

    } // if list has elements

    // API: ChartFactory.createPieChart(title, data, legend, tooltips, urls)
    chart = ChartFactory.createPieChart("Avg Test Time by Area", dataset, true, true, false);

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

    return chart;
}

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

/**
 * Generate a pie graph representing test counts for each product area. 
 *
 * @param   suites   List of test suites
 * @param   areas    List of product areas 
 * /* w  ww  .ja va2  s  . co m*/
 * @return  Pie graph representing build execution times across all builds 
 */
public static final JFreeChart getAverageAreaTestCountChart(Vector<CMnDbBuildData> builds,
        Vector<CMnDbTestSuite> suites, Vector<CMnDbFeatureOwnerData> areas) {
    JFreeChart chart = null;

    // Collect the average of all test types 
    Hashtable countAvg = new Hashtable();

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

        // Collect test data for each of the suites in the list 
        Enumeration suiteList = suites.elements();
        while (suiteList.hasMoreElements()) {

            // Process the data for the current suite
            CMnDbTestSuite suite = (CMnDbTestSuite) suiteList.nextElement();
            Integer testCount = new Integer(suite.getTestCount());
            CMnDbFeatureOwnerData area = null;

            // Iterate through each product area to determine who owns this suite
            CMnDbFeatureOwnerData currentArea = null;
            Iterator iter = areas.iterator();
            while (iter.hasNext()) {
                currentArea = (CMnDbFeatureOwnerData) iter.next();
                if (currentArea.hasFeature(suite.getGroupName())) {
                    Integer avgValue = null;
                    String areaName = currentArea.getDisplayName();
                    if (countAvg.containsKey(areaName)) {
                        Integer oldAvg = (Integer) countAvg.get(areaName);
                        avgValue = oldAvg + testCount;
                    } else {
                        avgValue = testCount;
                    }
                    countAvg.put(areaName, avgValue);

                }
            }

        } // while list has elements

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

    } // if list has elements

    // API: ChartFactory.createPieChart(title, data, legend, tooltips, urls)
    chart = ChartFactory.createPieChart("Avg Test Count by Area", dataset, true, true, false);

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

    return chart;
}

From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java

/**    
* Creates a pie chart with default settings that compares 2 datasets.      
* The colour of each section will be determined by the move from the value    
* for the same key in <code>previousDataset</code>. ie if value1 > value2     
* then the section will be in green (unless <code>greenForIncrease</code>     
* is <code>false</code>, in which case it would be <code>red</code>).      
* Each section can have a shade of red or green as the difference can be     
* tailored between 0% (black) and percentDiffForMaxScale% (bright     
* red/green).    //from  ww  w . ja  v  a  2s .  com
* <p>    
* For instance if <code>percentDiffForMaxScale</code> is 10 (10%), a     
* difference of 5% will have a half shade of red/green, a difference of     
* 10% or more will have a maximum shade/brightness of red/green.    
* <P>    
* The chart object returned by this method uses a {@link PiePlot} instance    
* as the plot.    
* <p>    
* Written by <a href="mailto:opensource@objectlab.co.uk">Benoit     
* Xhenseval</a>.    
*    
* @param title  the chart title (<code>null</code> permitted).    
* @param dataset  the dataset for the chart (<code>null</code> permitted).    
* @param previousDataset  the dataset for the last run, this will be used     
*                         to compare each key in the dataset    
* @param percentDiffForMaxScale scale goes from bright red/green to black,    
*                               percentDiffForMaxScale indicate the change     
*                               required to reach top scale.    
* @param greenForIncrease  an increase since previousDataset will be     
*                          displayed in green (decrease red) if true.    
* @param legend  a flag specifying whether or not a legend is required.    
* @param tooltips  configure chart to generate tool tips?    
* @param locale  the locale (<code>null</code> not permitted).    
* @param subTitle displays a subtitle with colour scheme if true    
* @param showDifference  create a new dataset that will show the %     
*                        difference between the two datasets.     
*    
* @return A pie chart.    
*     
* @since 1.0.7    
*/
public static JFreeChart createPieChart(String title, PieDataset dataset, PieDataset previousDataset,
        int percentDiffForMaxScale, boolean greenForIncrease, boolean legend, boolean tooltips, Locale locale,
        boolean subTitle, boolean showDifference) {

    PiePlot plot = new PiePlot(dataset);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale));
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));

    if (tooltips) {
        plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale));
    }

    List keys = dataset.getKeys();
    DefaultPieDataset series = null;
    if (showDifference) {
        series = new DefaultPieDataset();
    }

    double colorPerPercent = 255.0 / percentDiffForMaxScale;
    for (Iterator it = keys.iterator(); it.hasNext();) {
        Comparable key = (Comparable) it.next();
        Number newValue = dataset.getValue(key);
        Number oldValue = previousDataset.getValue(key);

        if (oldValue == null) {
            if (greenForIncrease) {
                plot.setSectionPaint(key, Color.green);
            } else {
                plot.setSectionPaint(key, Color.red);
            }
            if (showDifference) {
                series.setValue(key + " (+100%)", newValue);
            }
        } else {
            double percentChange = (newValue.doubleValue() / oldValue.doubleValue() - 1.0) * 100.0;
            double shade = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255
                    : Math.abs(percentChange) * colorPerPercent);
            if (greenForIncrease && newValue.doubleValue() > oldValue.doubleValue()
                    || !greenForIncrease && newValue.doubleValue() < oldValue.doubleValue()) {
                plot.setSectionPaint(key, new Color(0, (int) shade, 0));
            } else {
                plot.setSectionPaint(key, new Color((int) shade, 0, 0));
            }
            if (showDifference) {
                series.setValue(
                        key + " (" + (percentChange >= 0 ? "+" : "")
                                + NumberFormat.getPercentInstance().format(percentChange / 100.0) + ")",
                        newValue);
            }
        }
    }

    if (showDifference) {
        plot.setDataset(series);
    }

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    if (subTitle) {
        TextTitle subtitle = null;
        subtitle = new TextTitle("Bright " + (greenForIncrease ? "red" : "green") + "=change >=-"
                + percentDiffForMaxScale + "%, Bright " + (!greenForIncrease ? "red" : "green") + "=change >=+"
                + percentDiffForMaxScale + "%", new Font("SansSerif", Font.PLAIN, 10));
        chart.addSubtitle(subtitle);
    }

    return chart;
}

From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java

/**    
* Creates a pie chart with default settings that compares 2 datasets.      
* The colour of each section will be determined by the move from the value    
* for the same key in <code>previousDataset</code>. ie if value1 > value2     
* then the section will be in green (unless <code>greenForIncrease</code>     
* is <code>false</code>, in which case it would be <code>red</code>).      
* Each section can have a shade of red or green as the difference can be     
* tailored between 0% (black) and percentDiffForMaxScale% (bright     
* red/green).    /* ww w  .j  a  v  a2 s .  co  m*/
* <p>    
* For instance if <code>percentDiffForMaxScale</code> is 10 (10%), a     
* difference of 5% will have a half shade of red/green, a difference of     
* 10% or more will have a maximum shade/brightness of red/green.    
* <P>    
* The chart object returned by this method uses a {@link PiePlot} instance    
* as the plot.    
* <p>    
* Written by <a href="mailto:opensource@objectlab.co.uk">Benoit     
* Xhenseval</a>.    
*    
* @param title  the chart title (<code>null</code> permitted).    
* @param dataset  the dataset for the chart (<code>null</code> permitted).    
* @param previousDataset  the dataset for the last run, this will be used     
*                         to compare each key in the dataset    
* @param percentDiffForMaxScale scale goes from bright red/green to black,    
*                               percentDiffForMaxScale indicate the change     
*                               required to reach top scale.    
* @param greenForIncrease  an increase since previousDataset will be     
*                          displayed in green (decrease red) if true.    
* @param legend  a flag specifying whether or not a legend is required.    
* @param tooltips  configure chart to generate tool tips?    
* @param urls  configure chart to generate URLs?    
* @param subTitle displays a subtitle with colour scheme if true    
* @param showDifference  create a new dataset that will show the %     
*                        difference between the two datasets.     
*    
* @return A pie chart.    
*/
public static JFreeChart createPieChart(String title, PieDataset dataset, PieDataset previousDataset,
        int percentDiffForMaxScale, boolean greenForIncrease, boolean legend, boolean tooltips, boolean urls,
        boolean subTitle, boolean showDifference) {

    PiePlot plot = new PiePlot(dataset);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator());
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));

    if (tooltips) {
        plot.setToolTipGenerator(new StandardPieToolTipGenerator());
    }
    if (urls) {
        plot.setURLGenerator(new StandardPieURLGenerator());
    }

    List keys = dataset.getKeys();
    DefaultPieDataset series = null;
    if (showDifference) {
        series = new DefaultPieDataset();
    }

    double colorPerPercent = 255.0 / percentDiffForMaxScale;
    for (Iterator it = keys.iterator(); it.hasNext();) {
        Comparable key = (Comparable) it.next();
        Number newValue = dataset.getValue(key);
        Number oldValue = previousDataset.getValue(key);

        if (oldValue == null) {
            if (greenForIncrease) {
                plot.setSectionPaint(key, Color.green);
            } else {
                plot.setSectionPaint(key, Color.red);
            }
            if (showDifference) {
                series.setValue(key + " (+100%)", newValue);
            }
        } else {
            double percentChange = (newValue.doubleValue() / oldValue.doubleValue() - 1.0) * 100.0;
            double shade = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255
                    : Math.abs(percentChange) * colorPerPercent);
            if (greenForIncrease && newValue.doubleValue() > oldValue.doubleValue()
                    || !greenForIncrease && newValue.doubleValue() < oldValue.doubleValue()) {
                plot.setSectionPaint(key, new Color(0, (int) shade, 0));
            } else {
                plot.setSectionPaint(key, new Color((int) shade, 0, 0));
            }
            if (showDifference) {
                series.setValue(
                        key + " (" + (percentChange >= 0 ? "+" : "")
                                + NumberFormat.getPercentInstance().format(percentChange / 100.0) + ")",
                        newValue);
            }
        }
    }

    if (showDifference) {
        plot.setDataset(series);
    }

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    if (subTitle) {
        TextTitle subtitle = null;
        subtitle = new TextTitle("Bright " + (greenForIncrease ? "red" : "green") + "=change >=-"
                + percentDiffForMaxScale + "%, Bright " + (!greenForIncrease ? "red" : "green") + "=change >=+"
                + percentDiffForMaxScale + "%", new Font("SansSerif", Font.PLAIN, 10));
        chart.addSubtitle(subtitle);
    }

    return chart;
}

From source file:org.gridchem.client.gui.charts.UsageChart.java

/**
 * Returns a dataset representing the consumption of this project's
 * allocation by each collaborator including the current user.
 * /*  ww  w  .  j ava 2s .c om*/
 * @param project
 * @return
 */
private DefaultPieDataset createUserDataset(Hashtable<ProjectBean, List<CollaboratorBean>> projectCollabTable) {

    DefaultPieDataset pds = new DefaultPieDataset();

    Hashtable<String, Double> userUsageTable = new Hashtable<String, Double>();

    for (ProjectBean project : projectCollabTable.keySet()) {
        List<CollaboratorBean> collabs = projectCollabTable.get(project);

        for (CollaboratorBean collab : collabs) {
            String key = collab.getFirstName() + " " + collab.getLastName();
            if (userUsageTable.containsKey(key)) {
                double oldVal = userUsageTable.get(key).doubleValue();
                userUsageTable.remove(key);
                userUsageTable.put(key, new Double(oldVal + collab.getTotalUsage().getUsed()));
            } else {
                userUsageTable.put(key, new Double(collab.getTotalUsage().getUsed()));
            }
        }
    }

    // now put the tallies in the dataset
    for (String key : userUsageTable.keySet()) {
        pds.setValue(key, userUsageTable.get(key).doubleValue());
    }

    return pds;
}

From source file:jdefects.view.dialogs.ChartDisplayDialog.java

/**
 * Generate the data set for the chart/*from w ww .  j  a v  a  2 s . co  m*/
 * @return 
 *      the dataset generated 
 */
private PieDataset createDataset() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    String label = EMPTY_STRING;
    for (DefectStatus status : DefectStatus.values()) {
        if (status.equals(DefectStatus.OPEN)) {
            label = LanguageContent.chart_status_labels[1];
        } else if (status.equals(DefectStatus.REOPENED)) {
            label = LanguageContent.chart_status_labels[2];
        } else if (status.equals(DefectStatus.IN_PROGRESS)) {
            label = LanguageContent.chart_status_labels[3];
        } else if (status.equals(DefectStatus.ANALYSIS)) {
            label = LanguageContent.chart_status_labels[4];
        } else if (status.equals(DefectStatus.DEVELOPMENT)) {
            label = LanguageContent.chart_status_labels[5];
        } else if (status.equals(DefectStatus.PRE_INTEGRATION)) {
            label = LanguageContent.chart_status_labels[6];
        } else if (status.equals(DefectStatus.INTEGRATED)) {
            label = LanguageContent.chart_status_labels[7];
        } else if (status.equals(DefectStatus.VALIDATION)) {
            label = LanguageContent.chart_status_labels[8];
        } else if (status.equals(DefectStatus.DEFECT_MONITORING)) {
            label = LanguageContent.chart_status_labels[9];
        } else if (status.equals(DefectStatus.CLOSED)) {
            label = LanguageContent.chart_status_labels[10];
        } else { //dafault: UNKNOWN
            label = LanguageContent.chart_status_labels[0];
        }
        dataset.setValue(label, new Integer((int) map.get(status.name())));
    }
    return dataset;
}

From source file:nextapp.echo2.chart.testapp.testscreen.PieChartTest.java

public PieChartTest() {
    super(SplitPane.ORIENTATION_HORIZONTAL, new Extent(250, Extent.PX));
    setStyleName("DefaultResizable");

    ButtonColumn controlsColumn = new ButtonColumn();
    controlsColumn.setStyleName("TestControlsColumn");
    add(controlsColumn);//from  w  ww .  j  a v a2s .com

    DefaultKeyedValues values = new DefaultKeyedValues();
    values.addValue("Widgets", 500.2);
    values.addValue("Cubits", 216.0);
    values.addValue("Zonkits", 125.9);

    final DefaultPieDataset pieDataset = new DefaultPieDataset(new DefaultPieDataset(values));
    PiePlot piePlot = new PiePlot(pieDataset);

    final ChartDisplay chartDisplay = new ChartDisplay(piePlot);
    add(chartDisplay);

    controlsColumn.addButton("Set Width = 800px", new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            synchronized (chartDisplay) {
                chartDisplay.setWidth(new Extent(800));
            }
        }
    });

    controlsColumn.addButton("Set Width = null", new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            synchronized (chartDisplay) {
                chartDisplay.setWidth(null);
            }
        }
    });

    controlsColumn.addButton("Set Height = 600px", new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            synchronized (chartDisplay) {
                chartDisplay.setHeight(new Extent(600));
            }
        }
    });

    controlsColumn.addButton("Set Height = null", new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            synchronized (chartDisplay) {
                chartDisplay.setHeight(null);
            }
        }
    });

    controlsColumn.addButton("Update a Value", new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            synchronized (chartDisplay) {
                pieDataset.setValue("Cubits", Math.random() * 500);
            }
        }
    });
}