Example usage for org.jfree.data.xy XYSeriesCollection addSeries

List of usage examples for org.jfree.data.xy XYSeriesCollection addSeries

Introduction

In this page you can find the example usage for org.jfree.data.xy XYSeriesCollection addSeries.

Prototype

public void addSeries(XYSeries series) 

Source Link

Document

Adds a series to the collection and sends a DatasetChangeEvent to all registered listeners.

Usage

From source file:net.relet.freimap.LinkInfo.java

public void setLinkProfile(LinkedList<LinkData> lp) {

    XYSeries data = new XYSeries("etx");
    XYSeries avail = new XYSeries("avail");
    XYSeriesCollection datac = new XYSeriesCollection(data);
    datac.addSeries(avail);
    linkChart = ChartFactory.createXYLineChart("average link etx\r\naverage link availability", "time", "etx",
            datac, PlotOrientation.VERTICAL, false, false, false);
    sexupLayout(linkChart);// ww  w .ja va 2 s.c o m

    long first = lp.getFirst().time, last = lp.getLast().time, lastClock = first, count = 0, //number of samplis in aggregation timespan
            maxCount = 0; //max idem
    long aggregate = (last - first) / CHART_WIDTH; //calculate aggregation timespan: divide available timespan in CHART_WIDTH equal chunks
    double sum = 0;

    /* ok, this ain't effective, we do it just to pre-calculate maxCount */
    ListIterator<LinkData> li = lp.listIterator();
    while (li.hasNext()) {
        LinkData ld = li.next();
        count++;
        if (ld.time - lastClock > aggregate) {
            if (maxCount < count)
                maxCount = count;
            lastClock = ld.time;
            count = 0;
        }
    }

    //reset for second iteration
    count = 0;
    lastClock = first;

    //iterate again
    li = lp.listIterator();
    while (li.hasNext()) {
        LinkData ld = li.next();

        sum += ld.quality;
        count++;

        if (aggregate == 0)
            aggregate = 1000;//dirty hack
        if (ld.time - lastClock > aggregate) {
            for (long i = lastClock; i < ld.time - aggregate; i += aggregate) {
                data.add(i * 1000, (i == lastClock) ? sum / count : Double.NaN);
                avail.add(i * 1000, (i == lastClock) ? ((double) count / maxCount) : 0);
            }

            count = 0;
            sum = 0;
            lastClock = ld.time;
        }
    }

    status = STATUS_AVAILABLE;
}

From source file:org.optaplanner.examples.cheaptime.swingui.CheapTimePanel.java

private XYPlot createPeriodCostPlot(TangoColorFactory tangoColorFactory, CheapTimeSolution solution) {
    XYSeries series = new XYSeries("Power price");
    for (PeriodPowerPrice periodPowerPrice : solution.getPeriodPowerPriceList()) {
        series.add((double) periodPowerPrice.getPowerPriceMicros() / 1000000.0, periodPowerPrice.getPeriod());
    }/* w  w  w.j av a2 s  .c o m*/
    XYSeriesCollection seriesCollection = new XYSeriesCollection();
    seriesCollection.addSeries(series);
    XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES);
    renderer.setSeriesPaint(0, TangoColorFactory.ORANGE_1);
    renderer.setSeriesShape(0, ShapeUtilities.createDiamond(2.0F));
    NumberAxis domainAxis = new NumberAxis("Power price");
    return new XYPlot(seriesCollection, domainAxis, null, renderer);
}

From source file:org.picketlink.idm.performance.TestBase.java

protected void generateGraph(String filename, String subDir) {

    (new File(graphBaseDir + "/" + subDir)).mkdirs();

    XYSeries series = new XYSeries("XYGraph");

    long sum = 0;

    for (Map.Entry<Integer, Number> entry : measure.entrySet()) {
        series.add(entry.getKey(), entry.getValue());
        sum += (Long) entry.getValue();
    }/*  w  w w.ja  v a2  s . c om*/

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);

    JFreeChart chart = ChartFactory.createXYLineChart(filename, // Title
            "# of users", // x-axis Label
            "time to create one" + " ... S:" + sum + ", " + "A: " + ((double) sum / measure.size()), // y-axis
            // Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            false, // Show Legend
            false, // Use tooltips
            false // Configure chart to generate URLs?
    );
    try {
        ChartUtilities.saveChartAsPNG(new File(graphBaseDir + "/" + subDir + "/" + filename + ".png"), chart,
                1200, 800);
    } catch (IOException e) {
        System.err.println(e);
        System.err.println("Problem occurred creating chart.");
    }

}

From source file:app.Plot.java

public XYDataset createDataset(ArrayList<Integer> step, ArrayList<Double> frequency) {

    final XYSeriesCollection dataset = new XYSeriesCollection();
    final XYSeries c2 = new XYSeries("?2");
    for (int i = 0; i < 200; i++) {
        c2.add(step.get(i), frequency.get(i));
    }//from w  ww  .  j  a v  a  2  s .  c om
    dataset.addSeries(c2);
    return dataset;
}

From source file:statistics.distribution.ExponentialDistribution.java

private XYDataset getDataset() {
    XYSeriesCollection dataSet = new XYSeriesCollection();
    XYSeries xySeries = new XYSeries("CDF");
    double x = 0.0;
    for (int i = 0; i < 50; i++) {
        xySeries.add(x, CDF(x));//  w w w .  j a v  a  2 s.  com
        x += 0.2;
    }
    dataSet.addSeries(xySeries);
    return dataSet;
}

From source file:org.drugis.mtc.gui.results.ConvergencePlotsDialog.java

private JPanel createPanel() {
    final FormLayout layout = new FormLayout("pref:grow:fill", "p, 3dlu, p, 3dlu, p");
    final PanelBuilder builder = new PanelBuilder(layout);
    builder.setDefaultDialogBorder();/*from  w  w  w  . j  a v a 2 s.  co  m*/
    final CellConstraints cc = new CellConstraints();

    final XYSeriesCollection datasetRhat = new XYSeriesCollection();
    final XYSeriesCollection datasetVhatVsW = new XYSeriesCollection();
    datasetRhat.addSeries(d_rHatSeries);
    datasetVhatVsW.addSeries(d_vHatSeries);
    datasetVhatVsW.addSeries(d_wSeries);
    final JFreeChart rHatChart = createRhatChart(datasetRhat);
    final JFreeChart vHatvsWChart = createVhatVsWChart(datasetVhatVsW);
    final ChartPanel chartPanelRhat = new ChartPanel(rHatChart);
    final ChartPanel chartPanelVhatVsW = new ChartPanel(vHatvsWChart);
    chartPanelRhat.setVisible(true);
    chartPanelVhatVsW.setVisible(true);

    final JProgressBar bar = new TaskProgressBar(d_task);

    builder.add(bar, cc.xy(1, 1));
    builder.add(chartPanelRhat, cc.xy(1, 3));
    builder.add(chartPanelVhatVsW, cc.xy(1, 5));
    return builder.getPanel();
}

From source file:view.MainFrame.java

public void showChart(int N, double[] valuesY, double[] valuesX, String axisX, String axisY, String graphName,
        String dataName) {//from w  ww.  j av  a2s .c  om

    graphPanel.removeAll();

    String serieName = dataName;
    String tittle = graphName;
    String xAxisName = axisX;
    String yAxisName = axisY;

    XYSeries dataSerie = new XYSeries(serieName);

    for (int i = 0; i < N; i++) {
        dataSerie.add(valuesX[i], valuesY[i]);
    }

    XYSeriesCollection sCollection = new XYSeriesCollection();
    sCollection.addSeries(dataSerie);

    //JFreeChart jfreechart = ChartFactory.createScatterPlot(tittle, xAxisName, yAxisName, sCollection);
    JFreeChart jfreechart = ChartFactory.createHistogram(tittle, xAxisName, yAxisName, sCollection,
            PlotOrientation.VERTICAL, true, true, false);
    ChartPanel panel = new ChartPanel(jfreechart);
    panel.setVisible(true);

    graphPanel.add(panel);
    graphPanel.setLayout(new GridLayout(1, 0));
    graphPanel.validate();
    graphPanel.setVisible(true);
}

From source file:model.LineChart.java

/**
 * Creates a sample dataset./*  w  w  w  .j a  v  a2s  . com*/
 *
 * @return a sample dataset.
 */
private XYDataset createDataset(final Scenario[] scenarios, final int quantity, final int size,
        final ScenarioType type, final int variableOption, final String machine) {

    final XYSeries series1 = new XYSeries("Sequential");
    final XYSeries series7 = new XYSeries("");
    final XYSeries series2 = new XYSeries("Parallel");
    final XYSeries series3 = new XYSeries("Sequential Dilts");
    final XYSeries series4 = new XYSeries("Parallel Dilts");
    final XYSeries series5 = new XYSeries("Sequential Jonathan");
    final XYSeries series6 = new XYSeries("Parallel Jonathan");

    System.out.println("Scenarios size: " + scenarios.length);

    for (Scenario scenario : scenarios) {

        switch (variableOption) {
        case 0:
            if (scenario.getMachine().equals(machine)) {
                if (scenario.getSize() == size && scenario.getType() == type) {
                    System.out.println(scenario.getQuantity() + " " + scenario.getSize() + " "
                            + scenario.getType() + " " + scenario.getSequentialAverageTime());
                    series1.add(scenario.getQuantity(), scenario.getSequentialAverageTime());
                    series2.add(scenario.getQuantity(), scenario.getParallelAverageTime());

                }
            }
            break;
        case 1:
            if (scenario.getMachine().equals(machine)) {
                if (scenario.getQuantity() == quantity && scenario.getType() == type) {
                    System.out.println(scenario.getQuantity() + " " + scenario.getSize() + " "
                            + scenario.getType() + " " + scenario.getSequentialAverageTime());
                    series1.add(scenario.getSize(), scenario.getSequentialAverageTime());
                    series2.add(scenario.getSize(), scenario.getParallelAverageTime());

                }
            }
            break;
        case 2:
            if (scenario.getMachine().equals(machine)) {
                if (scenario.getQuantity() == quantity && scenario.getSize() == size) {
                    System.out.println(scenario.getQuantity() + " " + scenario.getSize() + " "
                            + scenario.getType() + " " + scenario.getSequentialAverageTime());
                    series1.add(0, scenario.getSequentialAverageTime());
                    series2.add(1, scenario.getParallelAverageTime());
                }
            }
            break;
        default:
            if (scenario.getQuantity() == quantity && scenario.getSize() == size
                    && scenario.getType() == type) {
                System.out.println("qtd: " + scenario.getQuantity() + " size: " + scenario.getSize() + " type: "
                        + scenario.getType() + " seq: " + scenario.getSequentialAverageTime() + " par: "
                        + scenario.getParallelAverageTime() + " machine: " + scenario.getMachine());
                if ("caio".equals(scenario.getMachine())) {
                    series1.add(100, scenario.getSequentialAverageTime());
                    series2.add(100, scenario.getParallelAverageTime());
                } else if ("dilts".equals(scenario.getMachine())) {
                    series3.add(200, scenario.getSequentialAverageTime());
                    series4.add(200, scenario.getParallelAverageTime());
                } else if ("Jonathan".equals(scenario.getMachine())) {
                    series5.add(300, scenario.getSequentialAverageTime());
                    series6.add(300, scenario.getParallelAverageTime());
                }
            }
            break;

        }

    }

    final XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series1);
    dataset.addSeries(series7);
    dataset.addSeries(series2);

    if (variableOption == 3) {
        dataset.addSeries(series3);
        dataset.addSeries(series4);
        dataset.addSeries(series5);
        dataset.addSeries(series6);
    }

    return dataset;

}

From source file:org.drools.planner.benchmark.statistic.bestscore.BestScoreStatistic.java

private CharSequence writeGraphStatistic(File solverStatisticFilesDirectory, String baseName) {
    NumberAxis xAxis = new NumberAxis("Time millis spend");
    xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat());
    NumberAxis yAxis = new NumberAxis("Score");
    yAxis.setAutoRangeIncludesZero(false);
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    int seriesIndex = 0;
    for (Map.Entry<String, BestScoreStatisticListener> listenerEntry : bestScoreStatisticListenerMap
            .entrySet()) {/*from  w ww . j av  a2s  . c o  m*/
        String configName = listenerEntry.getKey();
        XYSeries series = new XYSeries(configName);
        List<BestScoreStatisticPoint> statisticPointList = listenerEntry.getValue().getStatisticPointList();
        for (BestScoreStatisticPoint statisticPoint : statisticPointList) {
            long timeMillisSpend = statisticPoint.getTimeMillisSpend();
            Score score = statisticPoint.getScore();
            Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score);
            if (scoreGraphValue != null) {
                series.add(timeMillisSpend, scoreGraphValue);
            }
        }
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        seriesCollection.addSeries(series);
        plot.setDataset(seriesIndex, seriesCollection);
        XYItemRenderer renderer;
        // No direct lines between 2 points
        renderer = new XYStepRenderer();
        if (statisticPointList.size() <= 1) {
            // Workaround for https://sourceforge.net/tracker/?func=detail&aid=3387330&group_id=15494&atid=115494
            renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES);
        }
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;
    }
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart(baseName + " best score statistic", JFreeChart.DEFAULT_TITLE_FONT, plot,
            true);
    BufferedImage chartImage = chart.createBufferedImage(1024, 768);
    File graphStatisticFile = new File(solverStatisticFilesDirectory, baseName + "BestScoreStatistic.png");
    OutputStream out = null;
    try {
        out = new FileOutputStream(graphStatisticFile);
        ImageIO.write(chartImage, "png", out);
    } catch (IOException e) {
        throw new IllegalArgumentException("Problem writing graphStatisticFile: " + graphStatisticFile, e);
    } finally {
        IOUtils.closeQuietly(out);
    }
    return "  <img src=\"" + graphStatisticFile.getName() + "\"/>\n";
}

From source file:org.gdms.usm.view.ProgressFrame.java

private ChartPanel createChartPanel(String valueName, XYSeries data) {
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(data);
    JFreeChart chart = ChartFactory.createXYLineChart(null, "Step", valueName, dataset,
            PlotOrientation.VERTICAL, true, true, false);
    chart.removeLegend();/*from   www .  j  a v a2 s .  c o m*/
    return new ChartPanel(chart);
}