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

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

Introduction

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

Prototype

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

Source Link

Document

Adds a value to the table.

Usage

From source file:Controlador.ControladorLecturas.java

public JInternalFrame graficoHumedadSuelo() {
    DefaultCategoryDataset defaultCategoryDataset = new DefaultCategoryDataset();
    for (Object row : vectorHumedadSuelo()) {
        int grados = Integer.parseInt(((Vector) row).elementAt(0).toString());
        String rowKey = "Sensor 1";
        String columnKey = ((Vector) row).elementAt(1).toString();
        defaultCategoryDataset.addValue(grados, rowKey, columnKey);
    }/*w ww.java  2 s  .  co m*/
    JFreeChart jFreeChart = ChartFactory.createLineChart(null, "Hora", "Humedad", defaultCategoryDataset,
            PlotOrientation.VERTICAL, true, true, true);
    ChartPanel chartPanel = new ChartPanel(jFreeChart);
    JInternalFrame jInternalFrame = new JInternalFrame("Grafico de Humedad del Suelo", true, true, true, true);
    jInternalFrame.add(chartPanel, BorderLayout.CENTER);
    jInternalFrame.pack();
    return jInternalFrame;
}

From source file:edu.coeia.charts.BarChartPanel.java

private DefaultCategoryDataset createSampleDataset() {
    final DefaultCategoryDataset result = new DefaultCategoryDataset();

    double total = getTotal();

    for (Map.Entry<String, Double> aMap : map.entrySet()) {

        String str = aMap.getValue().toString();
        double counts = Double.valueOf(str).doubleValue();
        double percentage = getPercentage(counts, total);

        result.addValue(percentage, "Number of Messages (%)", aMap.getKey());
    }//from ww  w.j a  v a 2  s. com

    return result;
}

From source file:org.openscience.cdk.applications.taverna.weka.classification.EvaluateClassificationResultsAsPDFActivity.java

@Override
public void work() throws Exception {
    // Get input/*  www. j a va  2s  . c o  m*/
    String[] options = ((String) this.getConfiguration()
            .getAdditionalProperty(CDKTavernaConstants.PROPERTY_SCATTER_PLOT_OPTIONS)).split(";");
    List<File> modelFiles = this.getInputAsFileList(this.INPUT_PORTS[0]);
    List<Instances> trainDatasets = this.getInputAsList(this.INPUT_PORTS[1], Instances.class);
    List<Instances> testDatasets = null;
    if (options[0].equals("" + TEST_TRAININGSET_PORT)) {
        testDatasets = this.getInputAsList(this.INPUT_PORTS[2], Instances.class);
    }
    String directory = modelFiles.get(0).getParent();
    // Do work
    ChartTool chartTool = new ChartTool();
    WekaTools tools = new WekaTools();
    ArrayList<String> resultFiles = new ArrayList<String>();
    DefaultCategoryDataset meanClassificationChartset = new DefaultCategoryDataset();
    int fileIndex = 0;
    while (!modelFiles.isEmpty()) {
        fileIndex++;
        List<Object> chartObjects = new LinkedList<Object>();
        LinkedList<Double> trainPercentage = new LinkedList<Double>();
        LinkedList<Double> testPercentage = new LinkedList<Double>();
        for (int j = 0; j < trainDatasets.size(); j++) {
            File modelFile = modelFiles.remove(0);
            Classifier classifier = (Classifier) SerializationHelper.read(modelFile.getPath());
            DefaultCategoryDataset chartDataset = new DefaultCategoryDataset();
            String summary = "";
            Instances trainset = trainDatasets.get(j);
            Instances tempset = Filter.useFilter(trainset, tools.getIDRemover(trainset));
            Evaluation trainsetEval = new Evaluation(tempset);
            trainsetEval.evaluateModel(classifier, tempset);
            String setname = "Training set (" + String.format("%.2f", trainsetEval.pctCorrect()) + "%)";
            this.createDataset(trainset, classifier, chartDataset, trainPercentage, setname);
            summary += "Training set:\n\n";
            summary += trainsetEval.toSummaryString(true);
            double ratio = 100;
            if (testDatasets != null) {
                Instances testset = testDatasets.get(j);
                tempset = Filter.useFilter(testset, tools.getIDRemover(testset));
                Evaluation testEval = new Evaluation(trainset);
                testEval.evaluateModel(classifier, tempset);
                setname = "Test set (" + String.format("%.2f", testEval.pctCorrect()) + "%)";
                this.createDataset(testset, classifier, chartDataset, testPercentage, setname);
                summary += "\nTest set:\n\n";
                summary += testEval.toSummaryString(true);
                ratio = trainset.numInstances() / (double) (trainset.numInstances() + testset.numInstances())
                        * 100;
            }
            String header = classifier.getClass().getSimpleName() + "\n Training set ratio: "
                    + String.format("%.2f", ratio) + "\n" + modelFile.getName();
            chartObjects.add(chartTool.createBarChart(header, "Class", "Correct classified (%)", chartDataset));
            chartObjects.add(summary);
        }
        DefaultCategoryDataset percentageChartSet = new DefaultCategoryDataset();

        double mean = 0;
        for (int i = 0; i < trainPercentage.size(); i++) {
            percentageChartSet.addValue(trainPercentage.get(i), "Training Set", "" + (i + 1));
            mean += trainPercentage.get(i);
        }
        mean /= trainPercentage.size();
        meanClassificationChartset.addValue(mean, "Training Set", "" + fileIndex);
        mean = 0;
        for (int i = 0; i < testPercentage.size(); i++) {
            percentageChartSet.addValue(testPercentage.get(i), "Test Set", "" + (i + 1));
            mean += testPercentage.get(i);
        }
        mean /= testPercentage.size();
        meanClassificationChartset.addValue(mean, "Test Set", "" + fileIndex);
        chartObjects.add(chartTool.createLineChart("Overall Percentages", "Index", "Correct Classified (%)",
                percentageChartSet, false, true));
        File file = FileNameGenerator.getNewFile(directory, ".pdf", "ScatterPlot");
        chartTool.writeChartAsPDF(file, chartObjects);
        resultFiles.add(file.getPath());
    }
    JFreeChart meanChart = chartTool.createLineChart("Overall Percentages", "Model Index",
            "Correct Classified (%)", meanClassificationChartset, false, true);
    File file = FileNameGenerator.getNewFile(directory, ".pdf", "ScatterPlot");
    chartTool.writeChartAsPDF(file, Collections.singletonList((Object) meanChart));
    resultFiles.add(file.getPath());
    // Set output
    this.setOutputAsStringList(resultFiles, this.OUTPUT_PORTS[0]);
}

From source file:sernet.gs.ui.rcp.main.bsi.views.chart.MaturitySpiderChart.java

protected Object createSpiderDataset() throws CommandException {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    MassnahmenSummaryHome dao = new MassnahmenSummaryHome();

    Map<String, Double> items2 = dao.getControlMaxGroups(elmt);
    Set<Entry<String, Double>> entrySet2 = items2.entrySet();
    for (Entry<String, Double> entry : sort(entrySet2)) {
        dataset.addValue(entry.getValue(), Messages.MaturitySpiderChart_1, entry.getKey());
    }/* w  ww  .  j a  v  a2s  .com*/

    Map<String, Double> items4 = dao.getControlGoal2Groups(elmt);
    Set<Entry<String, Double>> entrySet4 = items4.entrySet();
    for (Entry<String, Double> entry : sort(entrySet4)) {
        dataset.addValue(entry.getValue(), Messages.MaturitySpiderChart_2, entry.getKey());
    }

    Map<String, Double> items3 = dao.getControlGoal1Groups(elmt);
    Set<Entry<String, Double>> entrySet3 = items3.entrySet();
    for (Entry<String, Double> entry : sort(entrySet3)) {
        dataset.addValue(entry.getValue(), Messages.MaturitySpiderChart_3, entry.getKey());
    }

    Map<String, Double> items1 = dao.getControlGroups(elmt);
    Set<Entry<String, Double>> entrySet = items1.entrySet();

    for (Entry<String, Double> entry : sort(entrySet)) {
        dataset.addValue(entry.getValue(), Messages.MaturitySpiderChart_4, entry.getKey());
    }

    return dataset;
}

From source file:jenkins.plugins.livingdoc.chart.ProjectSummaryChart.java

private DefaultCategoryDataset aggregateDataset() {

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (SummaryBuildReportBean summary : summaries) {
        Statistics stats = summary.getBuildSummary().getStatistics();
        String label = String.format("#%d", summary.getBuildId());
        int failureCount = stats.exceptionCount() + stats.wrongCount();

        dataset.addValue(stats.rightCount(), SUCCESS_SERIES_NAME, label);
        dataset.addValue(failureCount, FAILURES_SERIES_NAME, label);

        adjustUpperBound(stats);/*  w w w. ja  va 2  s  .  c o m*/
        adjustLowerBound(stats, failureCount);
    }

    return dataset;
}

From source file:be.pendragon.j2s.seventhcontinent.plot.jfreechart.JFreeChartPlotter.java

@Override
public void plot(Statistics[] stats, String[] seriesNames, String title, File outputFile) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int series = 0; series < stats.length; series++) {
        for (int pct = 1; pct <= 100; pct++) {
            double pctValue = stats[series].getPercentile(pct); // # of stars
            if (series > 0) {
                pctValue = pctValue - stats[series - 1].getPercentile(pct); // deltas are stackables
            }// www.j a  va2s. com
            dataset.addValue(pctValue, seriesNames[series], new Integer(pct));
        }
    }
    final JFreeChart barChart = ChartFactory.createStackedBarChart(title, "%", "# stars", dataset);
    try {
        ChartUtilities.saveChartAsJPEG(outputFile, barChart, width, height);
    } catch (IOException ex) {
        //      LOG.log(Level.SEVERE, "Plotting chart to file", ex);
        throw new RuntimeException("Plotting with JFreeChart chart to file", ex);
    }
}

From source file:Controlador.ControladorLecturas.java

public JInternalFrame graficoHumedadAmbiental() {
    DefaultCategoryDataset defaultCategoryDataset = new DefaultCategoryDataset();
    for (Object row : vectorHumedadAmbiental()) {
        int porcentaje = Integer.parseInt(((Vector) row).elementAt(0).toString());
        String rowKey = "Sensor 1";
        String columnKey = ((Vector) row).elementAt(1).toString();
        defaultCategoryDataset.addValue(porcentaje, rowKey, columnKey);
    }/*from w  w w .  j a v  a  2  s.  c  o m*/
    JFreeChart jFreeChart = ChartFactory.createLineChart(null, "Hora", "Porcentaje Humedad",
            defaultCategoryDataset, PlotOrientation.VERTICAL, true, true, true);
    ChartPanel chartPanel = new ChartPanel(jFreeChart);
    JInternalFrame jInternalFrame = new JInternalFrame("Grafico de Humedad Ambiental", true, true, true, true);
    jInternalFrame.add(chartPanel, BorderLayout.CENTER);
    jInternalFrame.pack();
    return jInternalFrame;
}

From source file:com.pureinfo.srm.reports.impl.CategoryChartBuilder.java

private CategoryDataset createDataset() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (Iterator iter = m_sDatas.iterator(); iter.hasNext();) {
        ReportResult result = (ReportResult) iter.next();
        String sName = result.getName();
        double dblValue = result.getValue();
        dataset.addValue(dblValue, m_sYXxisName, sName);
        m_dblMaxData = dblValue > m_dblMaxData ? dblValue : m_dblMaxData;
    }/*from   w w  w. j  av a 2s  . c  o m*/
    return dataset;
}

From source file:org.n52.oxf.render.sos.AnimatedMapBarChartRenderer.java

private CategoryDataset createDataset(int indexOfProperty, String timeString, ObservedValueTuple tuple) {
    String category = timeString;

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (int j = 0; j < observedProperties.length; j++) {
        if (j == indexOfProperty) {
            dataset.addValue((Number) tuple.getValue(indexOfProperty), "Series " + j, category);
        } else {/*w  w  w. j  av  a 2s  .c o  m*/
            dataset.addValue(null, "Series " + j, category);
        }
    }
    return dataset;
}

From source file:org.yccheok.jstock.gui.portfolio.DividendSummaryBarChartJDialog.java

private CategoryDataset createDataset() {
    /* Year to Dividend */
    final Map<Integer, Double> m = new HashMap<Integer, Double>();
    final int size = this.dividendSummary.size();

    for (int i = 0; i < size; i++) {
        final Dividend dividend = this.dividendSummary.get(i);

        // There might be newly added empty records in dividendSummary.
        // Ignore them.
        if (dividend.amount <= 0) {
            continue;
        }/*from  w w w  .j  a v a  2 s. c o  m*/

        int selectedIndex = this.jComboBox1.getSelectedIndex();
        if (selectedIndex != 0) {
            // selectedIndex - 1, as the first item in combo box is "All Stock(s)".
            final Code code = this.stockInfos.get(selectedIndex - 1).code;
            if (false == dividend.stockInfo.code.equals(code)) {
                continue;
            }
        }

        final int year = dividend.date.getYear();
        if (m.containsKey(year)) {
            m.put(year, m.get(year) + dividend.amount);
        } else {
            m.put(year, dividend.amount);
        }
    }

    List<Integer> list = new ArrayList<Integer>(m.keySet());
    java.util.Collections.sort(list);

    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int year : list) {
        final String category = "" + year;
        final String series = this.jComboBox1.getSelectedItem().toString();
        dataset.addValue(m.get(year), series, category);
    }

    return dataset;
}