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:com.indicator_engine.controller.GraphController.java

private PieDataset createDataSet(EntitySpecification entitySpecification) {
    DefaultPieDataset dpd = new DefaultPieDataset();
    GLAEntityDao glaEntityBean = (GLAEntityDao) appContext.getBean("glaEntity");
    log.info("PIE CHART DATA : STARTED \n" + entitySpecification.getHql());
    dpd.setValue(entitySpecification.getIndicatorName(),
            glaEntityBean.findNumber(entitySpecification.getHql()));
    /*if(entitySpecification.getQuestionsContainer().getGenQueries().size() !=0){
    for(GenQuery genQuery : entitySpecification.getQuestionsContainer().getGenQueries()) {
        dpd.setValue(genQuery.getIndicatorName(), glaEntityBean.findNumber(genQuery.getQuery()));
    }// ww  w  . j a  v  a 2s. c o m
    }*/
    return dpd;
}

From source file:com.neu.css.view.ViewPatientDetailsJPanel.java

private void showGraphButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showGraphButtonActionPerformed
    // TODO add your handling code here:
    int selectedRow = jTable1.getSelectedRow();
    if (selectedRow >= 0) {
        VitalSign vitalSign = (VitalSign) jTable1.getValueAt(selectedRow, 0);
        DefaultPieDataset defaultPieDataset = new DefaultPieDataset();
        defaultPieDataset.setValue("Repiratory Rate", vitalSign.getRespiratoryRate());
        defaultPieDataset.setValue("Heart Rate", vitalSign.getHeartRate());
        defaultPieDataset.setValue("Blood Pressure", vitalSign.getBloodPressure());
        defaultPieDataset.setValue("Weight", vitalSign.getWeight());
        JFreeChart jFreeChart = ChartFactory.createPieChart("Vital Sign Graphical Representation",
                defaultPieDataset, true, true, Locale.US);
        PiePlot piePlot = (PiePlot) jFreeChart.getPlot();
        ChartFrame chartFrame = new ChartFrame("Pie Chart", jFreeChart);
        chartFrame.setVisible(true);//from   ww w  . j  a v  a 2 s  .c  om
        chartFrame.setSize(450, 500);

    } else {
        JOptionPane.showMessageDialog(null, Consts.NO_SELECTION_VALIDATE_MESSAGE, "Warning",
                JOptionPane.WARNING_MESSAGE);
    }
}

From source file:dao.Graficos.java

public JFreeChart GraficoPizza(String titulo, List<CarCapContas> contas, FiltroData filtro) {

    DefaultPieDataset data = new DefaultPieDataset();

    for (CarCapContas i : contas) {

        if (i.getContaTipo().equals(TipoConta.Entrada)) {

            data.setValue("" + TipoConta.Entrada.toString(), i.getContaValorPago());

        } else if (i.getContaTipo().equals(TipoConta.Saida)) {

            data.setValue("" + TipoConta.Saida.toString(), i.getContaValorPago());

        }// w ww.jav a  2  s.co  m
    }

    JFreeChart chart = ChartFactory.createPieChart3D(titulo, data, true, true, true);

    return chart;
}

From source file:user.Query.java

public DefaultPieDataset getBlijdorpTweets() {
    query = "   SELECT " + "    (" + " SELECT count(*) " + " FROM Tweet " + " WHERE AREA != ' no area' "
            + " AND ANIMAL = ' no animal' " + " AND User_name = ' Diergaarde Blijdorp'" + " AND " + time
            + " ) AS Tweets_About_Areas, (" + " SELECT count(*) " + " FROM Tweet "
            + " WHERE  ANIMAL != ' no animal' " + " AND User_name = ' Diergaarde Blijdorp' " + " AND " + time
            + " ) AS Tweets_About_Animals," + " (" + " SELECT count(*) " + " FROM Tweet "
            + " WHERE  ANIMAL = ' no animal' " + " AND  AREA = ' no area' "
            + " AND User_name = ' Diergaarde Blijdorp' " + "  AND " + time + " ) AS 'Other_Tweets'" + " ;";
    DefaultPieDataset dataset = new DefaultPieDataset();
    try {/*from  ww w .jav a 2 s .  c o  m*/
        ResultSet resultSet = executeQuery(query);
        ResultSetMetaData metaData = resultSet.getMetaData();
        while (resultSet.next()) {
            int count = metaData.getColumnCount();
            for (int i = 1; i <= count; i++) {
                dataset.setValue(metaData.getColumnName(i), Integer.parseInt(resultSet.getString(i)));
            }
        }
    } catch (SQLException ex) {
    }
    return dataset;
}

From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.interactivepiechartfilters.JfreeDivaPieChartFilter.java

private String initPieChart(int width, int height) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    for (int x = 0; x < labels.length; x++) {
        dataset.setValue(labels[x], new Double(values[x]));

    }/*  w w  w  .  j a  va  2 s.c om*/
    plot = new PiePlot(dataset);
    plot.setNoDataMessage("No data available");
    plot.setCircular(true);

    plot.setLabelGap(0);

    plot.setLabelFont(new Font("Verdana", Font.BOLD, 15));
    plot.setLabelGenerator(new PieSectionLabelGenerator() {

        @Override
        public String generateSectionLabel(PieDataset pd, Comparable cmprbl) {
            return valuesMap.get(cmprbl.toString());
        }

        @Override
        public AttributedString generateAttributedSectionLabel(PieDataset pd, Comparable cmprbl) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });
    plot.setSimpleLabels(true);

    plot.setLabelBackgroundPaint(null);
    plot.setLabelShadowPaint(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelOutlinePaint(null);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setInteriorGap(0);
    plot.setShadowPaint(Color.WHITE);
    plot.setOutlineVisible(false);
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(1.2f));
    plot.setInteriorGap(0.05);
    for (String label : labels) {
        plot.setSectionPaint(label, defaultKeyColorMap.get(label));
    }

    chart = new JFreeChart(plot);
    chart.setTitle(
            new TextTitle(Local_Filter_Manager.getFilterTitle(filter_Id), new Font("Verdana", Font.BOLD, 13)));
    chart.setBorderPaint(null);
    chart.setBackgroundPaint(null);
    chart.getLegend().setFrame(BlockBorder.NONE);
    chart.getLegend().setItemFont(new Font("Verdana", Font.PLAIN, 12));
    String imgUrl = saveToFile(chart, width, height);

    return imgUrl;

}

From source file:fuel.gui.stats.StationStatsPanel.java

private void refreshGraphs() {
    graphContainer.removeAll();//from  ww  w.j  ava2  s  .c o  m
    DefaultPieDataset usageDataset = new DefaultPieDataset();
    try {
        for (Station station : database.getStations()) {
            ResultSet thisStation = database
                    .Query("SELECT SUM(liter) FROM fuelrecords WHERE stationId = " + station.getId(), true);
            thisStation.next();
            usageDataset.setValue(station.toString(), thisStation.getInt("1"));
        }

    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause());
    }
    JFreeChart usagePieChart = ChartFactory.createPieChart3D("", usageDataset, true, true, false);
    PiePlot3D plot3 = (PiePlot3D) usagePieChart.getPlot();
    plot3.setForegroundAlpha(0.6f);
    //plot3.setCircular(true);

    JPanel usagePieChartPanel = new ChartPanel(usagePieChart);
    usagePieChartPanel.setBorder(
            BorderFactory.createTitledBorder(BorderFactory.createTitledBorder("Tankstation verhouding")));
    usagePieChartPanel.setPreferredSize(new java.awt.Dimension(320, 240));

    DefaultPieDataset fuelDataset = new DefaultPieDataset();
    try {
        ResultSet numberResults = database.Query("SELECT DISTINCT typeOfGas FROM fuelrecords", true);
        while (numberResults.next()) {
            ResultSet thisStation = database.Query("SELECT SUM(liter) FROM fuelrecords WHERE typeOfGas = '"
                    + numberResults.getString("typeOfGas") + "'", true);
            thisStation.next();
            fuelDataset.setValue(numberResults.getString("typeOfGas"), thisStation.getInt("1"));
        }

    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause());
    }
    JFreeChart fuelPieChart = ChartFactory.createPieChart3D("", fuelDataset, true, true, false);
    PiePlot3D plot2 = (PiePlot3D) fuelPieChart.getPlot();
    plot2.setForegroundAlpha(0.6f);
    //plot3.setCircular(true);

    JPanel fuelPieChartPanel = new ChartPanel(fuelPieChart);
    fuelPieChartPanel.setBorder(
            BorderFactory.createTitledBorder(BorderFactory.createTitledBorder("Brandstof verhouding")));
    fuelPieChartPanel.setPreferredSize(new java.awt.Dimension(320, 240));

    DefaultCategoryDataset barDataset = new DefaultCategoryDataset();
    try {
        ResultSet motorThing = database.Query("SELECT cost/liter,date FROM fuelrecords ORDER BY date ASC",
                true);
        while (motorThing.next()) {
            barDataset.addValue(motorThing.getDouble("1"), motorThing.getString("date"), "Prijs per liter");
        }

    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause());
    }

    JFreeChart barChart = ChartFactory.createBarChart3D("", // chart title
            "", // domain axis label
            "Aantal", // range axis label
            barDataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips?
            false // URLs?
    );
    CategoryPlot plot = barChart.getCategoryPlot();
    BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    ChartPanel barChartPanel = new ChartPanel(barChart);
    barChartPanel.getChartRenderingInfo().setEntityCollection(null);
    barChartPanel.setBorder(BorderFactory.createTitledBorder("Prijs per liter"));
    barChartPanel.setPreferredSize(new java.awt.Dimension(320, 240));

    JPanel piePanel = new JPanel(new GridLayout(0, 2));
    piePanel.add(usagePieChartPanel);
    piePanel.add(fuelPieChartPanel);
    graphContainer.add(piePanel);
    graphContainer.add(barChartPanel);
    revalidate();
    repaint();
}

From source file:velo.ejb.seam.action.HomeActionsBean.java

public void createChart() {
    ResourceList rl = new ResourceList();
    rl.getResource().setActive(true);//ww w  .  j av  a  2 s  .  co m
    rl.initialize();
    List<Resource> resources = rl.getResultList();

    //Retrieve a list of tasks from last day
    TaskList tl = new TaskList();
    List<Task> tasks = tl.getResultList();

    //build the summaries
    Map<String, Long> rTasks = new HashMap<String, Long>();

    for (Task currTask : tasks) {
        if (currTask instanceof ResourceTask) {
            ResourceTask rt = (ResourceTask) currTask;

            if (!rTasks.containsKey(rt.getResourceUniqueName())) {
                rTasks.put(rt.getResourceUniqueName(), new Long(0));
            }

            rTasks.put(rt.getResourceUniqueName(), rTasks.get(rt.getResourceUniqueName()) + 1);
        }
    }

    final DefaultPieDataset dataset = new DefaultPieDataset();
    for (Resource currResource : resources) {
        if (rTasks.containsKey(currResource.getUniqueName())) {
            dataset.setValue(currResource.getDisplayName() + "("
                    + rTasks.get(currResource.getUniqueName()).longValue() + ")",
                    rTasks.get(currResource.getUniqueName()));
        } else {
            dataset.setValue(currResource.getDisplayName() + "(0)", 0);
        }

    }

    final JFreeChart chart = ChartFactory.createPieChart("Tasks Amount (1 last day) per resource", // chart title
            dataset, // dataset
            true, // include legend
            true, false);
    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setNoDataMessage("No data available");

    try {
        this.chart = ChartUtilities.encodeAsPNG(chart.createBufferedImage(400, 400));
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:com.estate.pdf.Page.java

protected void drawTaxPie(Rectangle rct, double totalValue, double tax, String taxLabel, String netLabel) {
    double taxPercent = (tax / totalValue) * 100;
    double netValuePercent = 100 - taxPercent;

    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue(taxLabel, taxPercent);
    dataset.setValue(netLabel, netValuePercent);

    PiePlot3D plot = new PiePlot3D(dataset);
    plot.setLabelGenerator(new StandardPieItemLabelGenerator());
    plot.setInsets(new Insets(0, 5, 5, 5));
    plot.setToolTipGenerator(new CustomeGenerators.CustomToolTipGenerator());
    plot.setLabelGenerator(new CustomeGenerators.CustomLabelGenerator());
    plot.setSectionPaint(0, new Color(pgRed));
    plot.setSectionPaint(1, new Color(pgGreen));
    plot.setForegroundAlpha(.6f);// w ww .  j av a 2 s . c  o m
    plot.setOutlinePaint(Color.white);
    plot.setBackgroundPaint(Color.white);

    JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    chart.setBackgroundPaint(Color.white);
    chart.setAntiAlias(true);

    Rectangle page = rct;

    try {
        Image img = Image.getInstance(chart.createBufferedImage((int) page.getWidth(), (int) page.getHeight()),
                null);
        drawDiagram(img, rct, 0, 72);
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }

}

From source file:UserInterface.CustomerRole.CustomerTaxJPanel.java

public void displayChart(Date date1) {
    int total = 0;
    int k;//  ww  w . java2 s .c om
    int count = 0;
    int avg = 0;

    Sensor s = (Sensor) jTable1.getValueAt(0, 0);
    Date b = s.getDate();
    DateFormat formatter = new SimpleDateFormat("MM/dd/yy");
    Date date = new Date();
    try {
        date = formatter.parse("12/11/16");
    } catch (Exception e) {

    }
    //date = 
    System.out.println(jTable1.getValueAt(0, 5));
    System.out.println(jTable1.getValueAt(0, 4));
    list = new ArrayList<>();

    for (int l = 0; l < jTable1.getRowCount(); l++) {
        if (date.getDate() == b.getDate()) {
            Sensor s1 = (Sensor) jTable1.getValueAt(l, 0);
            total = total + s1.getCurrentEmissionCO2();
            count++;
        }
    }
    avg = total / count;
    list.add(avg);

    int avg1 = 0;

    for (int l = 0; l < jTable1.getRowCount(); l++) {
        if (date.getDate() == b.getDate()) {
            Sensor s1 = (Sensor) jTable1.getValueAt(l, 0);
            total = total + s1.getCurrentEmissionCO2();
            count++;
        }
    }

    avg = total / count;
    list.add(avg);
    for (int l = 0; l < jTable1.getRowCount(); l++) {
        if (date.getDate() == b.getDate()) {
            Sensor s1 = (Sensor) jTable1.getValueAt(l, 0);
            total = total + s1.getNormalCO2();
            count++;
        }
    }
    avg1 = total / count;
    int avg3 = 0;
    for (int l = 0; l < jTable1.getRowCount(); l++) {
        if (date.getDate() == b.getDate()) {
            Sensor s1 = (Sensor) jTable1.getValueAt(l, 0);
            total = total + s1.getCurrentEmissionNOx();
            count++;
        }
    }
    avg3 = total / count;

    int avg4 = 0;
    for (int l = 0; l < jTable1.getRowCount(); l++) {
        if (date.getDate() == b.getDate()) {
            Sensor s1 = (Sensor) jTable1.getValueAt(l, 0);
            total = total + s1.getNormalNOx();
            count++;
        }
    }
    avg4 = total / count;

    int avg5 = 0;
    for (int l = 0; l < jTable1.getRowCount(); l++) {
        if (date.getDate() == b.getDate()) {
            Sensor s1 = (Sensor) jTable1.getValueAt(l, 0);
            total = total + s1.getSolarCurrentEmissionCO2();
            count++;
        }
    }
    avg5 = total / count;
    int avg6 = 0;

    for (int l = 0; l < jTable1.getRowCount(); l++) {
        if (date.getDate() == b.getDate()) {
            Sensor s1 = (Sensor) jTable1.getValueAt(l, 0);
            total = total + s1.getSolarNormalCO2();
            count++;
        }
    }

    avg6 = total / count;
    int avg7 = 0;
    for (int l = 0; l < jTable1.getRowCount(); l++) {
        if (date.getDate() == b.getDate()) {
            Sensor s1 = (Sensor) jTable1.getValueAt(l, 0);
            total = total + s1.getSolarCurrentEmissionNOx();
            count++;
        }
    }
    avg7 = total / count;
    int avg8 = 0;
    for (int l = 0; l < jTable1.getRowCount(); l++) {
        if (date.getDate() == b.getDate()) {
            Sensor s1 = (Sensor) jTable1.getValueAt(l, 0);
            total = total + s1.getSolarNormalNOx();
            count++;
        }
    }
    avg8 = total / count;

    int combo = avg + avg3;
    int combo1 = avg5 + avg7;

    DefaultPieDataset dataset22 = new DefaultPieDataset();
    dataset22.setValue("Fuel Emission", new Integer(combo));
    dataset22.setValue("Solar Emission ", new Integer(combo1));

    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 Comparison from different sources", chart22);
    frame33.setVisible(true);
    frame33.setSize(500, 400);

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(avg, b, "curr CO2");
    dataset.setValue(avg1, b, "normal CO2");
    dataset.setValue(avg3, b, "current NOx");
    dataset.setValue(avg4, b, "normal NOx");
    //dataset.setValue(a1,b1,"current");
    JFreeChart chart = ChartFactory.createBarChart("Normal Fuel Emission Chart", "CO2 Emission", "in (g/KM)",
            dataset, PlotOrientation.VERTICAL, false, false, false);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.BLACK);
    ChartFrame frame = new ChartFrame("Bar Chart for Customer", chart);
    frame.setVisible(true);
    frame.setSize(500, 400);

    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
    dataset1.setValue(avg5, b, "curr CO2");
    dataset1.setValue(avg6, b, "normal CO2");
    dataset1.setValue(avg7, b, "current NOx");
    dataset1.setValue(avg8, b, "normal NOx");
    //dataset.setValue(a1,b1,"current");
    JFreeChart chart2 = ChartFactory.createBarChart("Solar Emission Chart", "CO2 Emission", "in (g/KM)",
            dataset1, PlotOrientation.VERTICAL, false, false, false);
    CategoryPlot p1 = chart.getCategoryPlot();
    p1.setRangeGridlinePaint(Color.BLACK);
    ChartFrame frame1 = new ChartFrame("Bar Chart for Customer", chart2);
    frame1.setVisible(true);
    frame1.setSize(500, 400);
}

From source file:view.ViewReportUI.java

private PieDataset createDataset() {

    // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    DefaultPieDataset result = new DefaultPieDataset();
    InvoiceDAO dao = null;//from   w ww  .ja v  a2 s  . c  o  m
    try {

        HashMap<String, Double> value = new InvoiceDAO().getTotalTillNow();
        FileManager manager = new FileManager();
        String[] categories = manager.getFileContent("Database/category.txt");

        for (String key : value.keySet()) {

            result.setValue(key + "$ " + value.get(key), value.get(key));

        }
    } catch (SQLException ex) {
        Logger.getLogger(ViewReportUI.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(ViewReportUI.class.getName()).log(Level.SEVERE, null, ex);
    }
    return result;

}