Example usage for org.jfree.data.category DefaultCategoryDataset setValue

List of usage examples for org.jfree.data.category DefaultCategoryDataset setValue

Introduction

In this page you can find the example usage for org.jfree.data.category DefaultCategoryDataset setValue.

Prototype

public void setValue(double value, Comparable rowKey, Comparable columnKey) 

Source Link

Document

Adds or updates a value in the table and sends a DatasetChangeEvent to all registered listeners.

Usage

From source file:kcse_2013_results.BarChartExample.java

public static void main(String[] args) {
    // Create a simple Bar chart
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(6, "Profit", "Jane");
    dataset.setValue(7, "Profit", "Tom");
    dataset.setValue(8, "Profit", "Jill");
    dataset.setValue(5, "Profit", "John");
    dataset.setValue(12, "Profit", "Fred");
    JFreeChart chart = ChartFactory.createBarChart("Comparison between Salesman", "Salesman", "Profit", dataset,
            PlotOrientation.VERTICAL, false, true, false);

    final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    final int width = screenSize.width;
    final int height = screenSize.height;
    try {/*from w  w w  . java 2s  . c  o m*/
        ChartUtilities.saveChartAsJPEG(new File("C:\\Users\\Wachira\\Desktop\\chart.jpg"), chart, width,
                height);
    } catch (IOException e) {
        System.err.println("Problem occurred creating chart.");
    }
}

From source file:CalcoloRitardiLotti.java

public static void main(String[] args) {
    String id_ref = "cbededce-269f-48d2-8c25-2359bf246f42";
    String requestString = "http://dati.openexpo2015.it/catalog/api/action/datastore_search?resource_id="
            + id_ref;/* ww  w .  j  av a2s.  c  o m*/
    HttpClient client = HttpClientBuilder.create().build();
    HttpGet request = new HttpGet(requestString);
    try {

        HttpResponse response = client.execute(request);
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        String result = "";
        String resline = "";
        Calendar c = Calendar.getInstance();
        Date current = Date.valueOf(
                c.get(Calendar.YEAR) + "-" + (c.get(Calendar.MONTH) + 1) + "-" + c.get(Calendar.DAY_OF_MONTH));
        while ((resline = rd.readLine()) != null)
            result += resline;

        //System.out.println(jsonObject.toString());
        if (result != null) {
            JSONObject jsonObject = new JSONObject(result);
            JSONObject resultJson = (JSONObject) jsonObject.get("result");
            JSONArray records = (JSONArray) resultJson.get("records");
            Date temp1, temp2;
            //System.out.printf(records.toString());
            long diffInizioFineLavori;
            long ritardo;
            long den = (24 * 60 * 60 * 1000);
            JSONObject temp;

            DefaultCategoryDataset cdata = new DefaultCategoryDataset();
            String partialQuery;
            DefaultPieDataset data = new DefaultPieDataset();

            String totalQuery = "";
            int countSospesi = 0;
            int countConclusi = 0;
            int countVerifica = 0;
            int countInCorso = 0;
            int countCollaudo = 0;
            String stato;
            for (int i = 0; i < records.length(); i++) {
                temp = (JSONObject) records.get(i);
                temp1 = Date.valueOf((temp.getString("Data Consegna Lavori")).substring(0, 10));
                temp2 = Date.valueOf((temp.getString("Data Fine lavori")).substring(0, 10));
                diffInizioFineLavori = (long) (temp2.getTime() - temp1.getTime()) / den;
                stato = temp.getString("STATO");
                if (stato.equals("Concluso"))
                    countConclusi++;
                else if (stato.equals("In corso"))
                    countInCorso++;
                else if (stato.contains("Verifiche"))
                    countVerifica++;
                else if (stato.contains("Collaudo sospeso") || stato.contains("sospeso"))
                    countSospesi++;
                else
                    countCollaudo++;

                if (!temp.getString("STATO").equals("Concluso") && temp2.getTime() < current.getTime())
                    ritardo = (long) (current.getTime() - temp2.getTime()) / den;
                else
                    ritardo = 0;

                cdata.setValue(ritardo, String.valueOf(i + 1), String.valueOf(i + 1));
                System.out.println(
                        "Opera: " + temp.getString("Oggetto del lotto") + " | id: " + temp.getInt("_id"));
                System.out.println("Data consegna lavoro: " + temp.getString("Data Consegna Lavori")
                        + " | Data fine lavoro: " + temp.getString("Data Fine lavori"));
                System.out.println("STATO: " + temp.getString("STATO"));
                System.out.println("Differenza in giorni: " + diffInizioFineLavori
                        + " | Numero giorni contrattuali: " + temp.getString("numero di giorni contrattuali"));
                System.out.println("Ritardo accumulato: " + ritardo);

                System.out.println("----------------------------------");

                partialQuery = "\nid: " + temp.getInt("_id") + "\nOpera:" + temp.getString("Oggetto del lotto")
                        + "\n" + "Data consegna lavoro: " + temp.getString("Data Consegna Lavori")
                        + "Data fine lavoro: " + temp.getString("Data Fine lavori") + "\n" + "STATO: "
                        + temp.getString("STATO") + "\n" + "Differenza in giorni: " + diffInizioFineLavori
                        + " - Numero giorni contrattuali: " + temp.getString("numero di giorni contrattuali")
                        + "\n" + "Ritardo accumulato: " + ritardo + "\n"
                        + "----------------------------------\n";
                totalQuery = totalQuery + partialQuery;

            }

            JFreeChart chart1 = ChartFactory.createBarChart3D("RITARDI AL " + current, "Id lotto",
                    "ritardo(in giorni)", cdata);
            ChartRenderingInfo info = null;
            ChartUtilities.saveChartAsPNG(
                    new File(System.getProperty("user.dir") + "/istogramma" + current + ".png"), chart1, 1500,
                    1500, info, true, 10);
            FileUtils.writeStringToFile(new File(current + "_1.txt"), totalQuery);

            data.setValue("Conclusi: " + countConclusi, countConclusi);
            data.setValue("Sospeso: " + countSospesi, countSospesi);
            data.setValue("In Corso: " + countInCorso, countInCorso);
            data.setValue("Verifica: " + countVerifica, countVerifica);
            data.setValue("Collaudo: " + countCollaudo, countCollaudo);
            JFreeChart chart2 = ChartFactory.createPieChart3D("Statistiche del " + current, data, true, true,
                    true);
            ChartUtilities.saveChartAsPNG(new File(System.getProperty("user.dir") + "/pie" + current + ".png"),
                    chart2, 800, 450);

        }

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

From source file:com.ohalo.cn.awt.JFreeChartTest2.java

public static CategoryDataset createDataset() // ?
{
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(10, "a", "?");
    dataset.setValue(20, "b", "");
    dataset.setValue(40, "c", "?");
    dataset.setValue(15, "d", "");
    return dataset;
}

From source file:by.bsuir.group172301.matskevich.tour.util.PDFCreator.java

public static JFreeChart generateBarChart(int init, int posle) {
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

    dataSet.setValue(init, "?", "Before");
    dataSet.setValue(posle, "?", "After");

    JFreeChart chart = ChartFactory.createBarChart("Tendention", "Tests", "Quantity", dataSet,
            PlotOrientation.VERTICAL, false, true, false);

    return chart;
}

From source file:common.utility.ChartHelper.java

public static CategoryDataset createDataset() throws SQLException {

    // create the dataset...
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    ResultSet rs = new PersonDetailsDAO().selectAllPersonofArea();
    while (rs.next()) {
        dataset.setValue(rs.getDouble("NumOfCitizens"), "Area Code : " + rs.getString("AreaCode"), "Areas");
    }// w ww  . ja va  2  s  . c  o  m

    return dataset;

}

From source file:com.etest.view.tq.charts.SubjectTestLineChart.java

public static JFreeChart discriminationIndex(int tqCoverageId) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (CellItem ci : CellItemDAO.getItemAnalysisResult(tqCoverageId)) {
        dataset.setValue((int) (ci.getDiscriminationIndex() * 100), "Discrimination Index",
                String.valueOf(ci.getItemNo()));
    }/*w w w .j  av  a2s.c  o m*/

    JFreeChart chart = ChartFactory.createLineChart("Item Analysis Report", "Item No.",
            "Discrimination Index (%)", dataset, PlotOrientation.VERTICAL, true, true, false);

    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);

    // customise the range axis...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // customise the renderer...
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setFillPaint(Color.white);

    return chart;
}

From source file:com.etest.view.tq.charts.SubjectTestLineChart.java

public static JFreeChart difficultIndex(int tqCoverageId) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (CellItem ci : CellItemDAO.getItemAnalysisResult(tqCoverageId)) {
        dataset.setValue((int) (ci.getDifficultIndex() * 100), "Difficulty Index",
                String.valueOf(ci.getItemNo()));
    }// w  ww .ja v  a2s  . c o  m

    JFreeChart chart = ChartFactory.createLineChart("Item Analysis Report", "Item No.", "Difficulty Index (%)",
            dataset, PlotOrientation.VERTICAL, true, true, false);

    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);

    // customise the range axis...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // customise the renderer...
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setFillPaint(Color.white);

    return chart;
}

From source file:biblioteca.reportes.ChartCreator.java

public static DefaultCategoryDataset asignarBarDataset(ArrayList<String> Valores) {
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
    int size = Valores.size();
    size = (size <= 32) ? size : 32;/* w  w w  .j a va  2s .  com*/
    for (int i = 2; i < size; i += 2) {
        dataSet.setValue(Double.parseDouble(Valores.get(i + 1)), "Grafica", Valores.get(i));
    }
    return dataSet;
}

From source file:filtros.histograma.Histograma.java

public static void Apply(BufferedImage image, String savePath) {
    //Chamada do metodo que gera os dados do histograma
    GetData(image);// w w  w .  j  av  a2 s.  c  om

    //Dataset que gera o grafico
    DefaultCategoryDataset ds = new DefaultCategoryDataset();

    //Loop que percorre o array de dados do histograma
    for (int k = 0; k < data.length; k++) {
        //Adiciona o valor ao dataset
        ds.setValue(data[k], "Imagem", Integer.toString(data[k]));
    }

    //Gera o grafico
    JFreeChart grafico = ChartFactory.createLineChart("Histograma", "Tons de cinza", "Valor", ds,
            PlotOrientation.VERTICAL, true, true, false);

    //Salva o grafico em um arquivo de png
    try {
        OutputStream arquivo = new FileOutputStream(savePath);
        ChartUtilities.writeChartAsPNG(arquivo, grafico, 550, 400);
        arquivo.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.jolbox.benchmark.BenchmarkMain.java

/**
 * @param title /*  w  w w . j av a 2s .com*/
 * @param filename 
 * @param results 
 */
private static void plotBarGraph(String title, String filename, long[] results) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (ConnectionPoolType poolType : ConnectionPoolType.values()) {
        dataset.setValue(results[poolType.ordinal()], "ms", poolType);
    }
    JFreeChart chart = ChartFactory.createBarChart(title, "Connection Pool", "Time (ms)", dataset,
            PlotOrientation.VERTICAL, false, true, false);
    try {
        String fname = System.getProperty("java.io.tmpdir") + File.separator + filename;
        ChartUtilities.saveChartAsPNG(new File(fname), chart, 1024, 768);
        System.out.println("******* Saved chart to: " + fname);
    } catch (IOException e) {
        e.printStackTrace();
        System.err.println("Problem occurred creating chart.");
    }
}