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:i2p.bote.web.PeerInfoTag.java

private String createRelayChart(RelayPeer[] relayPeers) throws IOException {
    RingPlot plot;//from w w  w .  j  a  v a2 s.  co m
    if (relayPeers.length == 0) {
        DefaultPieDataset dataset = new DefaultPieDataset();
        dataset.setValue("", 100);

        plot = new RingPlot(dataset);
        plot.setSectionPaint("", Color.gray);
    } else {
        int good = 0;
        int untested = 0;
        for (RelayPeer relayPeer : relayPeers) {
            int reachability = relayPeer.getReachability();
            if (reachability == 0)
                untested += 1;
            else if (reachability > 80)
                good += 1;
        }
        int bad = relayPeers.length - good - untested;

        DefaultPieDataset dataset = new DefaultPieDataset();
        if (good > 0)
            dataset.setValue(_t("Good"), good);
        if (bad > 0)
            dataset.setValue(_t("Unreliable"), bad);
        if (untested > 0)
            dataset.setValue(_t("Untested"), untested);

        plot = new RingPlot(dataset);
        plot.setSectionPaint(_t("Good"), Color.green);
        plot.setSectionPaint(_t("Unreliable"), Color.red);
        plot.setSectionPaint(_t("Untested"), Color.orange);
    }
    plot.setLabelGenerator(null);
    plot.setShadowGenerator(null);

    JFreeChart chart = new JFreeChart(_t("Relay Peers:"), JFreeChart.DEFAULT_TITLE_FONT, plot,
            relayPeers.length == 0 ? false : true);
    return ServletUtilities.saveChartAsPNG(chart, 400, 300, null);
}

From source file:gui.images.CodebookVectorProfilePanel.java

/**
 * Sets the data to be shown./*w  w w  .  j  av a2 s  .c  o  m*/
 *
 * @param occurrenceProfile Double array that is the neighbor occurrence
 * profile of this visual word.
 * @param codebookIndex Integer that is the index of this visual word.
 * @param classColors Color[] of class colors.
 * @param classNames String[] of class names.
 */
public void setResults(double[] occurrenceProfile, int codebookIndex, Color[] classColors,
        String[] classNames) {
    int numClasses = Math.min(classNames.length, occurrenceProfile.length);
    this.codebookIndex = codebookIndex;
    this.occurrenceProfile = occurrenceProfile;
    DefaultPieDataset pieData = new DefaultPieDataset();
    for (int cIndex = 0; cIndex < numClasses; cIndex++) {
        pieData.setValue(classNames[cIndex], occurrenceProfile[cIndex]);
    }
    JFreeChart chart = ChartFactory.createPieChart3D("codebook vect " + codebookIndex, pieData, true, true,
            false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    PieRenderer prend = new PieRenderer(classColors);
    prend.setColor(plot, pieData);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(140, 140));
    chartPanel.setVisible(true);
    chartPanel.revalidate();
    chartPanel.repaint();
    JPanel jp = new JPanel();
    jp.setPreferredSize(new Dimension(140, 140));
    jp.setMinimumSize(new Dimension(140, 140));
    jp.setMaximumSize(new Dimension(140, 140));
    jp.setSize(new Dimension(140, 140));
    jp.setLayout(new FlowLayout());
    jp.add(chartPanel);
    jp.setVisible(true);
    jp.validate();
    jp.repaint();

    JFrame frame = new JFrame();
    frame.setBackground(Color.WHITE);
    frame.setUndecorated(true);
    frame.getContentPane().add(jp);
    frame.pack();
    BufferedImage bi = new BufferedImage(jp.getWidth(), jp.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = bi.createGraphics();
    jp.print(graphics);
    graphics.dispose();
    frame.dispose();
    imPanel.removeAll();
    imPanel.setImage(bi);
    imPanel.setVisible(true);
    imPanel.revalidate();
    imPanel.repaint();
}

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  w  w  .  j av a 2 s.  c  om*/

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

From source file:Logic.FinanceController.java

public void drawCostPieChart(String date) {
    int[] values;
    values = getFinacialRecords(date);//from www . j a  va  2s.  c  om
    double purcahse = new Double(-(values[1]));
    double disposal = new Double(-(values[2]));
    double salary = new Double(-(values[3]));

    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Purcahses", purcahse);
    dataset.setValue("Disposal of Inventory", disposal);
    dataset.setValue("Salaries", salary);

    JFreeChart chart = ChartFactory.createPieChart3D("Cost Breakdown", dataset, true, true, true);
    PiePlot3D p = (PiePlot3D) chart.getPlot();
    ChartFrame frame = new ChartFrame("Costs", chart);
    frame.setVisible(true);
    frame.setLocation(100, 100);
    frame.setSize(400, 400);
}

From source file:cz.zcu.kiv.eegdatabase.logic.controller.history.GraphController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    log.debug("Processing creating pie graph");
    String graphType = "";

    List<DownloadStatistic> topDownloadedFilesList = null;
    boolean isGroupAdmin;
    long countFile = 0;

    graphType = request.getParameter("graphType");
    int groupId = Integer.parseInt(request.getParameter("groupId"));
    isGroupAdmin = auth.userIsGroupAdmin();
    response.setContentType("image/png");

    topDownloadedFilesList = historyDao.getTopDownloadHistory(ChoiceHistory.valueOf(graphType), isGroupAdmin,
            groupId);/*from w  w  w  . ja va  2 s.  c  o  m*/

    DefaultPieDataset dataset = new DefaultPieDataset();
    if (groupId != -1) {
        for (int i = 0; i < topDownloadedFilesList.size(); i++) {
            dataset.setValue(topDownloadedFilesList.get(i).getFileName(),
                    new Long(topDownloadedFilesList.get(i).getCount()));
            countFile = countFile + topDownloadedFilesList.get(i).getCount();
        }

        if (historyDao.getCountOfFilesHistory(ChoiceHistory.valueOf(graphType), isGroupAdmin,
                groupId) > countFile) {
            dataset.setValue("Other",
                    historyDao.getCountOfFilesHistory(ChoiceHistory.valueOf(graphType), isGroupAdmin, groupId)
                            - countFile);
        }
    }
    JFreeChart chart = ChartFactory.createPieChart3D("Daily downloads", // chart title
            dataset, // data
            true, // include legend
            true, false);

    PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setStartAngle(290);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    plot.setNoDataMessage("No data to display");

    ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 600, 400);
    response.getOutputStream().close();
    return null;
}

From source file:Connexion.ChartDocteur.java

public ChartDocteur() {

    try {/* w w w .  j a v  a2 s  . c o  m*/
        Class.forName("com.mysql.jdbc.Driver");
    } catch (ClassNotFoundException e) {
        /* Grer les ventuelles erreurs ici. */
    }
    int a = 0;
    int b = 0;
    int c = 0;
    int d = 0;
    int f = 0;
    int g = 0;
    try {
        ResultSet resultat1 = this.connect
                .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)
                .executeQuery("SELECT specialite FROM docteur WHERE specialite =  'Cardiologue'");
        // on rcupre le nombre de lignes de la requte
        if (resultat1.last()) {
            a = resultat1.getRow();
        }
        System.out.println(a);

    } catch (SQLException e) {
        e.printStackTrace();
    }
    try {
        ResultSet resultat2 = this.connect
                .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)
                .executeQuery("SELECT specialite FROM docteur WHERE specialite =  'Traumatologue'");
        // on rcupre le nombre de lignes de la requte
        if (resultat2.last()) {
            b = resultat2.getRow();
        }
        System.out.println(b);

    } catch (SQLException e) {
        e.printStackTrace();
    }
    try {

        ResultSet resultat3 = this.connect
                .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)
                .executeQuery("SELECT specialite FROM docteur WHERE specialite =  'Pneumologue'");
        // on rcupre le nombre de lignes de la requte
        if (resultat3.last()) {
            c = resultat3.getRow();
        }
        System.out.println(c);

    } catch (SQLException e) {
        e.printStackTrace();
    }

    try {

        ResultSet resultat4 = this.connect
                .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)
                .executeQuery("SELECT specialite FROM docteur WHERE specialite =  'Orthopediste'");
        // on rcupre le nombre de lignes de la requte
        if (resultat4.last()) {
            d = resultat4.getRow();
        }
        System.out.println(d);

    } catch (SQLException e) {
        e.printStackTrace();
    }

    try {

        ResultSet resultat5 = this.connect
                .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)
                .executeQuery("SELECT specialite FROM docteur WHERE specialite =  'Radiologue'");
        // on rcupre le nombre de lignes de la requte
        if (resultat5.last()) {
            f = resultat5.getRow();
        }
        System.out.println(f);

    } catch (SQLException e) {
        e.printStackTrace();
    }

    try {

        ResultSet resultat6 = this.connect
                .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)
                .executeQuery("SELECT specialite FROM docteur WHERE specialite =  'Anesthesiste'");
        // on rcupre le nombre de lignes de la requte
        if (resultat6.last()) {
            g = resultat6.getRow();
        }
        System.out.println(g);

    } catch (SQLException e) {
        e.printStackTrace();
    }
    DefaultPieDataset union = new DefaultPieDataset();

    //remplir l'ensemble

    union.setValue("Cardiologue", a);
    union.setValue("Traumatologue", b);
    union.setValue("Pneumologue", c);
    union.setValue("Orthopediste", d);
    union.setValue("Radiologue", f);
    union.setValue("Anesthesiste", g);

    JFreeChart repart = ChartFactory.createPieChart3D("Nombre de mdecin par spcialit", union, true, true,
            false);
    ChartPanel crepart = new ChartPanel(repart);
    this.add(crepart);
    this.pack();
    this.setVisible(true);
}

From source file:org.psystems.dicom.browser.server.stat.UseagStoreChartServlet.java

public JFreeChart getChart() {

    PreparedStatement psSelect = null;

    try {//from  www. j  a v a2 s. c  om

        Connection connection = Util.getConnection("main", getServletContext());
        long dcmSizes = 0;
        long imgSizes = 0;
        //
        // ALL_IMAGE_SIZE
        // ALL_DCM_SIZE

        // psSelect = connection
        // .prepareStatement("SELECT ID, METRIC_NAME, METRIC_DATE, METRIC_VALUE_LONG "
        // + " FROM WEBDICOM.DAYSTAT WHERE METRIC_NAME = ?");

        psSelect = connection.prepareStatement(
                "SELECT SUM(METRIC_VALUE_LONG) S " + " FROM WEBDICOM.DAYSTAT WHERE METRIC_NAME = ?");

        psSelect.setString(1, "ALL_DCM_SIZE");
        ResultSet rs = psSelect.executeQuery();
        while (rs.next()) {
            dcmSizes = rs.getLong("S");
        }
        rs.close();

        psSelect.setString(1, "ALL_IMAGE_SIZE");
        rs = psSelect.executeQuery();
        while (rs.next()) {
            imgSizes = rs.getLong("S");
        }
        rs.close();

        String dcmRootDir = getServletContext().getInitParameter("webdicom.dir.src");
        long totalSize = new File(dcmRootDir).getTotalSpace(); //TODO !
        long freeSize = new File(dcmRootDir).getFreeSpace();
        long busySize = totalSize - freeSize;

        //         System.out.println("!!! totalSize=" + totalSize + " freeSize="+freeSize);

        long diskEmpty = freeSize - imgSizes - dcmSizes;

        //         double KdiskEmpty = (double)diskEmpty/(double)totalSize;
        //         System.out.println("!!! " + KdiskEmpty);

        double KdiskBusi = (double) busySize / (double) totalSize * 100;
        //         System.out.println("!!! KdiskBusi=" + KdiskBusi);

        double KdcmSizes = (double) dcmSizes / (double) totalSize * 100;
        //         System.out.println("!!! KdcmSizes=" + KdcmSizes);

        double KimgSizes = (double) imgSizes / (double) totalSize * 100;
        //         System.out.println("!!! KimgSizes=" + KimgSizes);

        double KdiskFree = (double) freeSize / (double) (totalSize - KdcmSizes - KimgSizes) * 100;
        //         System.out.println("!!! KdiskFree=" + KdiskFree);

        DefaultPieDataset dataset = new DefaultPieDataset();
        dataset.setValue("??? (DCM-) " + dcmSizes / 1000 + " .", KdcmSizes);
        dataset.setValue("? (JPG-) " + imgSizes / 1000 + " .", KimgSizes);
        dataset.setValue("?  " + busySize / 1000 + " .", KdiskBusi);
        dataset.setValue(" " + freeSize / 1000 + " .", KdiskFree);

        boolean legend = true;
        boolean tooltips = false;
        boolean urls = false;

        JFreeChart chart = ChartFactory.createPieChart(
                "? ? ??  ?",
                dataset, legend, tooltips, urls);

        chart.setBorderPaint(Color.GREEN);
        chart.setBorderStroke(new BasicStroke(5.0f));
        // chart.setBorderVisible(true);
        // chart.setPadding(new RectangleInsets(20 ,20,20,20));

        return chart;

    } catch (SQLException e) {
        logger.error(e);
        e.printStackTrace();
    } finally {

        try {
            if (psSelect != null)
                psSelect.close();
        } catch (SQLException e) {
            logger.error(e);
        }
    }
    return null;

}

From source file:UserInterface.ControlManagerRole.ControlManagerWorkAreaJPanel.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    int co2Level = 0;
    int noxLevel = 0;
    int comboBoston = 0;

    int co2Level1 = 0;
    int noxLevel1 = 0;
    int comboNewYork = 0;

    for (Network network : system.getNetworkList()) {
        if (network.getName().equalsIgnoreCase("boston")) {

            for (Customer customer : network.getCustomerDirectory().getCustomerDirectory()) {
                for (Sensor sensor : customer.getSensorDirectory().getSensorDirectory()) {
                    co2Level += sensor.getCurrentEmissionCO2();
                    noxLevel += sensor.getCurrentEmissionNOx();
                }// ww w .j  av  a2  s .  c  o  m
            }

        }

    }
    comboBoston = co2Level + noxLevel;

    for (Network network : system.getNetworkList()) {
        if (network.getName().equalsIgnoreCase("New York")) {

            for (Customer customer : network.getCustomerDirectory().getCustomerDirectory()) {
                for (Sensor sensor : customer.getSensorDirectory().getSensorDirectory()) {
                    co2Level1 += sensor.getCurrentEmissionCO2();
                    noxLevel1 += sensor.getCurrentEmissionNOx();
                }

            }

        }
    }
    comboNewYork = co2Level1 + noxLevel1;

    DefaultPieDataset dataset22 = new DefaultPieDataset();
    dataset22.setValue("Fuel Emission by Boston", new Integer(comboBoston));
    dataset22.setValue("Fuel Emission by New York ", new Integer(comboNewYork));

    JFreeChart chart22 = ChartFactory.createPieChart3D("Comparison Chart ", // chart title                   
            dataset22, // data 
            true, // include legend                   
            true, false);

    final PiePlot3D plot = (PiePlot3D) chart22.getPlot();
    plot.setStartAngle(270);
    plot.setForegroundAlpha(0.60f);
    plot.setInteriorGap(0.02);

    ChartFrame frame33 = new ChartFrame("3D Pie Chart for EMission Comparisonbetween two networks", chart22);
    frame33.setVisible(true);
    frame33.setSize(500, 400);

}

From source file:Vista.frm_MasVendidoCategoriaInforme.java

private void graficarDatos() {
    BL.Funciones_frm_MasVendido fun = new Funciones_frm_MasVendido();
    try {//from w  ww.j a  v a 2 s. c  o m
        DefaultPieDataset data = new DefaultPieDataset();
        for (int i = 0; i < id_categoria.length; i++) {
            data.setValue(categoria[i], fun.procentajeMasVendido(cantidad[i], sumatoriaCantidades()));
        }
        ChartPanel panel;
        JFreeChart chart = ChartFactory.createPieChart3D("PASTEL", data, true, true, true);
        panel = new ChartPanel(chart);
        panel.setBounds(0, 30, 450, 450);
        pan_derecha.add(panel);
    } catch (Exception e) {
    }
}

From source file:WeeklyReport.Sections.Commodities.java

private JFreeChart commodityChart() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    Map<Double, String> mp = new CargoTypeData().quotesByCommodityCBM();
    mp.entrySet().stream().forEach((mapEntry) -> {
        dataset.setValue(mapEntry.getValue(), mapEntry.getKey());
    });//from   w ww . ja  v  a  2s. c o m
    JFreeChart pieChart = ChartFactory.createPieChart3D("Commodities Quoted by Cubic Meter", dataset, true,
            true, false);

    PiePlot plot = (PiePlot) pieChart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);

    PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} cbm ({2})",
            new DecimalFormat("0.000"), new DecimalFormat("0%"));
    plot.setLabelGenerator(gen);

    return pieChart;
}