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:cachedataanalysis.FlowCache.java

public ArrayList<XYSeries> exportHitRateData() {

    XYSeries hitRateCount = new XYSeries(name + "(" + size + " entries)");

    for (int i = 0; i < hitRateRecord.size(); i++) {
        hitRateCount.add(i, hitRateRecord.get(i));
    }//from w  w w  .  ja  v a 2s. com

    XYSeriesCollection HitRateData = new XYSeriesCollection();
    HitRateData.addSeries(hitRateCount);

    ArrayList<XYSeries> result = new ArrayList<XYSeries>();
    result.add(hitRateCount);

    return result;
}

From source file:lu.lippmann.cdb.lab.mds.MDSViewBuilder.java

/**
 * // w ww . j ava 2 s  . c  o m
 * @param clusters
 */
public static void buildKMeansChart(final List<Instances> clusters) {
    final XYSeriesCollection dataset = new XYSeriesCollection();

    final JFreeChart chart = ChartFactory.createScatterPlot("", // title 
            "X", "Y", // axis labels 
            dataset, // dataset 
            PlotOrientation.VERTICAL, true, // legend? yes 
            true, // tooltips? yes 
            false // URLs? no 
    );

    final XYPlot xyPlot = (XYPlot) chart.getPlot();

    ((NumberAxis) xyPlot.getDomainAxis()).setTickUnit(new NumberTickUnit(2.0));
    ((NumberAxis) xyPlot.getRangeAxis()).setTickUnit(new NumberTickUnit(2.0));

    Attribute clsAttribute = null;
    int nbClass = 1;
    Instances cluster0 = clusters.get(0);
    if (cluster0.classIndex() != -1) {
        clsAttribute = cluster0.classAttribute();
        nbClass = clsAttribute.numValues();
    }
    if (nbClass <= 1) {
        dataset.addSeries(new XYSeries("Serie #1", false));
    } else {
        for (int i = 0; i < nbClass; i++) {
            dataset.addSeries(new XYSeries(clsAttribute.value(i), false));
        }
    }

    final XYToolTipGenerator gen = new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            return "TODO";
        }
    };

    for (int i = 0; i < nbClass; i++) {
        dataset.getSeries(i).clear();
        xyPlot.getRenderer().setSeriesToolTipGenerator(i, gen);
    }

    final int nbClusters = clusters.size();
    for (int i = 0; i < nbClusters; i++) {
        Instances instances = clusters.get(i);
        final int nbInstances = instances.numInstances();
        for (int j = 0; j < nbInstances; j++) {
            final Instance oInst = instances.instance(j);
            dataset.getSeries(i).add(oInst.value(0), oInst.value(1));
        }
    }

    final TitledBorder titleBorder = new TitledBorder("Kmeans of projection");
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setMouseWheelEnabled(true);
    chartPanel.setPreferredSize(new Dimension(1200, 900));
    chartPanel.setBorder(titleBorder);
    chartPanel.setBackground(Color.WHITE);

    JXFrame frame = new JXFrame();
    frame.getContentPane().add(chartPanel);
    frame.setVisible(true);
    frame.pack();

}

From source file:edu.ucla.stat.SOCR.applications.demo.StockSimulationApplication.java

protected XYSeriesCollection createDataset() {
    //System.out.println("stepS0="+stepS0);

    //System.out.println("createDataset start");
    s_serie = new XYSeries("S", false);
    for (int i = 0; i < numSs; i++) {
        s_serie.add(i, (S[i]));/*from w ww .j  a v  a 2 s.  c om*/
    }

    XYSeriesCollection ds = new XYSeriesCollection();
    ds.addSeries(s_serie);

    return ds;

}

From source file:org.optaplanner.benchmark.impl.statistic.single.constraintmatchtotalstepscore.ConstraintMatchTotalStepScoreSingleStatistic.java

@Override
public void writeGraphFiles(BenchmarkReport benchmarkReport) {
    List<Map<String, XYSeries>> constraintIdToWeightSeriesMapList = new ArrayList<Map<String, XYSeries>>(
            BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE);
    for (ConstraintMatchTotalStepScoreStatisticPoint point : getPointList()) {
        int scoreLevel = point.getScoreLevel();
        if (scoreLevel >= BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE) {
            continue;
        }//from   ww w  .j a v a  2s . c  o m
        while (scoreLevel >= constraintIdToWeightSeriesMapList.size()) {
            constraintIdToWeightSeriesMapList.add(new LinkedHashMap<String, XYSeries>());
        }
        Map<String, XYSeries> constraintIdToWeightSeriesMap = constraintIdToWeightSeriesMapList.get(scoreLevel);
        if (constraintIdToWeightSeriesMap == null) {
            constraintIdToWeightSeriesMap = new LinkedHashMap<String, XYSeries>();
            constraintIdToWeightSeriesMapList.set(scoreLevel, constraintIdToWeightSeriesMap);
        }
        String constraintId = point.getConstraintPackage() + ":" + point.getConstraintName();
        XYSeries weightSeries = constraintIdToWeightSeriesMap.get(constraintId);
        if (weightSeries == null) {
            weightSeries = new XYSeries(point.getConstraintName() + " weight");
            constraintIdToWeightSeriesMap.put(constraintId, weightSeries);
        }
        long timeMillisSpent = point.getTimeMillisSpent();
        weightSeries.add(timeMillisSpent, point.getWeightTotal());
    }
    graphFileList = new ArrayList<File>(constraintIdToWeightSeriesMapList.size());
    for (int scoreLevelIndex = 0; scoreLevelIndex < constraintIdToWeightSeriesMapList
            .size(); scoreLevelIndex++) {
        XYPlot plot = createPlot(benchmarkReport, scoreLevelIndex);
        // No direct ascending lines between 2 points, but a stepping line instead
        XYItemRenderer renderer = new XYStepRenderer();
        plot.setRenderer(renderer);
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        for (XYSeries series : constraintIdToWeightSeriesMapList.get(scoreLevelIndex).values()) {
            seriesCollection.addSeries(series);
        }
        plot.setDataset(seriesCollection);
        JFreeChart chart = new JFreeChart(singleBenchmarkResult.getName()
                + " constraint match total step score diff level " + scoreLevelIndex + " statistic",
                JFreeChart.DEFAULT_TITLE_FONT, plot, true);
        graphFileList.add(
                writeChartToImageFile(chart, "ConstraintMatchTotalStepScoreStatisticLevel" + scoreLevelIndex));
    }
}

From source file:org.optaplanner.benchmark.impl.statistic.subsingle.constraintmatchtotalstepscore.ConstraintMatchTotalStepScoreSubSingleStatistic.java

@Override
public void writeGraphFiles(BenchmarkReport benchmarkReport) {
    List<Map<String, XYSeries>> constraintIdToWeightSeriesMapList = new ArrayList<Map<String, XYSeries>>(
            BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE);
    for (ConstraintMatchTotalStepScoreStatisticPoint point : getPointList()) {
        int scoreLevel = point.getScoreLevel();
        if (scoreLevel >= BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE) {
            continue;
        }//from  w  w  w.j ava  2 s  .co  m
        while (scoreLevel >= constraintIdToWeightSeriesMapList.size()) {
            constraintIdToWeightSeriesMapList.add(new LinkedHashMap<String, XYSeries>());
        }
        Map<String, XYSeries> constraintIdToWeightSeriesMap = constraintIdToWeightSeriesMapList.get(scoreLevel);
        if (constraintIdToWeightSeriesMap == null) {
            constraintIdToWeightSeriesMap = new LinkedHashMap<String, XYSeries>();
            constraintIdToWeightSeriesMapList.set(scoreLevel, constraintIdToWeightSeriesMap);
        }
        String constraintId = point.getConstraintPackage() + ":" + point.getConstraintName();
        XYSeries weightSeries = constraintIdToWeightSeriesMap.get(constraintId);
        if (weightSeries == null) {
            weightSeries = new XYSeries(point.getConstraintName() + " weight");
            constraintIdToWeightSeriesMap.put(constraintId, weightSeries);
        }
        long timeMillisSpent = point.getTimeMillisSpent();
        weightSeries.add(timeMillisSpent, point.getWeightTotal());
    }
    graphFileList = new ArrayList<File>(constraintIdToWeightSeriesMapList.size());
    for (int scoreLevelIndex = 0; scoreLevelIndex < constraintIdToWeightSeriesMapList
            .size(); scoreLevelIndex++) {
        XYPlot plot = createPlot(benchmarkReport, scoreLevelIndex);
        // No direct ascending lines between 2 points, but a stepping line instead
        XYItemRenderer renderer = new XYStepRenderer();
        plot.setRenderer(renderer);
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        for (XYSeries series : constraintIdToWeightSeriesMapList.get(scoreLevelIndex).values()) {
            seriesCollection.addSeries(series);
        }
        plot.setDataset(seriesCollection);
        JFreeChart chart = new JFreeChart(subSingleBenchmarkResult.getName()
                + " constraint match total step score diff level " + scoreLevelIndex + " statistic",
                JFreeChart.DEFAULT_TITLE_FONT, plot, true);
        graphFileList.add(
                writeChartToImageFile(chart, "ConstraintMatchTotalStepScoreStatisticLevel" + scoreLevelIndex));
    }
}

From source file:br.com.una.apa.p02e01.Graph.java

/**
 * Creates a sample dataset.//from   w  ww. jav a  2 s.  com
 * 
 * @return a sample dataset.
 */
private XYDataset createDataset(ArrayList<Grafico> lista) {
    final XYSeriesCollection dataset = new XYSeriesCollection();

    for (int i = 0; i < lista.size(); i++) {
        XYSeries series = new XYSeries(lista.get(i).getNome());
        series.add(0, lista.get(i).getY());
        series.add(lista.get(i).getX(), lista.get(i).getY());
        dataset.addSeries(series);
    }

    return dataset;

}

From source file:org.gephi.statistics.plugin.PageRank.java

/**
 *
 * @return//from  www  .  j a va  2 s .  c o  m
 */
public String getReport() {
    //distribution of values
    Map<Double, Integer> dist = new HashMap<Double, Integer>();
    for (int i = 0; i < pageranks.length; i++) {
        Double d = pageranks[i];
        if (dist.containsKey(d)) {
            Integer v = dist.get(d);
            dist.put(d, v + 1);
        } else {
            dist.put(d, 1);
        }
    }

    //Distribution series
    XYSeries dSeries = ChartUtils.createXYSeries(dist, "PageRanks");

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

    JFreeChart chart = ChartFactory.createXYLineChart("PageRank Distribution", "Score", "Count", dataset,
            PlotOrientation.VERTICAL, true, false, false);
    chart.removeLegend();
    ChartUtils.decorateChart(chart);
    ChartUtils.scaleChart(chart, dSeries, true);
    String imageFile = ChartUtils.renderChart(chart, "pageranks.png");

    String report = "<HTML> <BODY> <h1>PageRank Report </h1> " + "<hr> <br />" + "<h2> Parameters: </h2>"
            + "Epsilon = " + epsilon + "<br>" + "Probability = " + probability + "<br> <h2> Results: </h2>"
            + imageFile + "<br /><br />" + "<h2> Algorithm: </h2>"
            + "Sergey Brin, Lawrence Page, <i>The Anatomy of a Large-Scale Hypertextual Web Search Engine</i>, in Proceedings of the seventh International Conference on the World Wide Web (WWW1998):107-117<br />"
            + "</BODY> </HTML>";

    return report;

}

From source file:sistemacontrole.LeituraEscritaCanais.java

public XYDataset createDataset() {
    try {//from www . j av a  2  s  .  c o m
        Thread.sleep(100);
    } catch (InterruptedException ex) {
        System.out.println("createDataset() exception: " + ex);
    }

    final XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(this.sinal_calculado);
    dataset.addSeries(this.sinal_tratado);
    return dataset;
}

From source file:com.opendoorlogistics.components.linegraph.LineGraphPanel.java

@Override
protected JFreeChart createChart(ODLTableReadOnly table, int[] rowFilter) {

    // split by key
    Map<String, List<XY>> lines = api.stringConventions().createStandardisedMap();

    if (rowFilter != null) {
        for (int row : rowFilter) {
            readLine(table, row, lines);
        }//from  w  ww.j  a v a  2  s  .c  o  m
    } else {
        int n = table.getRowCount();
        for (int row = 0; row < n; row++) {
            readLine(table, row, lines);
        }
    }

    XYSeriesCollection dataset = new XYSeriesCollection();

    for (Map.Entry<String, List<XY>> line : lines.entrySet()) {
        XYSeries s = new XYSeries(line.getKey());
        for (XY xy : line.getValue()) {
            s.add(xy.X, xy.Y);
        }
        dataset.addSeries(s);
    }

    JFreeChart chart = ChartFactory.createXYLineChart(
            api.stringConventions().isEmptyString(config.getTitle()) ? null : config.getTitle(), // chart title
            config.getXLabel(), // x axis label
            config.getYLabel(), // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, lines.size() > 0, // include legend
            true, // tooltips
            false // urls
    );

    // make lines thicker
    for (int i = 0; i < lines.size(); i++) {
        ((XYPlot) chart.getPlot()).getRenderer().setSeriesStroke(i, new BasicStroke(2));
    }

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.WHITE);

    return chart;
}

From source file:loldmg.GUI.MainFrame.java

private XYDataset createDataset(Champion dealer, Champion target) {

    final XYSeries series1 = new XYSeries("Damage per second done by auto attacks");
    AADPSGraph aadps = new AADPSGraph();

    BonusStats attackerBonusStats = new BonusStats();
    BonusStats targetBonusStats = new BonusStats();

    ArrayList<Item> purchasedItems = new ArrayList<Item>();

    int gold = 475;
    Ability aa = new Ability();
    Ability spear = new Ability();
    Ability heartseaker = new Ability();
    spear.ADdmg = 80;// w  w  w.j  a v a2 s  .  co  m
    spear.BONUSADratio = (float) 1.4;
    spear.scalesfromcdr = true;
    spear.cooldown = 4;
    heartseaker.ADdmg = 80;
    heartseaker.BONUSADratio = (float) 3.6;
    heartseaker.scalesfromcdr = true;
    heartseaker.cooldown = 10;
    aa.TOTALADratio = 1;
    aa.scalesfromas = true;
    rotation.add(aa);
    rotation.add(spear);
    rotation.add(heartseaker);
    for (int level = 1; level < 19; level++) {
        System.out.println("level: " + level + " gold: " + gold);

        ItemUtils buildgetter = new ItemUtils();
        purchasedItems = buildgetter.FindBestItemsToPurchase(purchasedItems, dealer, target, level, gold);
        gold = buildgetter.gold;
        gold += 200 + 100 * level / 3f;
        /*for (Item itemToPurchase : itemsToPurchase) {
        gold -= itemToPurchase.getGold().getBase();
        ItemUtils.PurchaseItem(purchasedItems, itemToPurchase);
        }*/
        attackerBonusStats = new BonusStats();
        for (Item i : purchasedItems) {
            attackerBonusStats.addstats(i.getStats());
        }
        series1.add(level, aadps.GetAADPS(dealer, attackerBonusStats, target, targetBonusStats, level));
    }

    final XYSeries series2 = new XYSeries("Target HP");
    if (ShowTargetHP.isSelected()) {

        new HealthGraph(target, new GraphInterface() {

            @Override
            public void NewData(int x, int value) {
                series2.add(x, value);
            }
        });
    }

    /*final XYSeries series2 = new XYSeries("Enemy health");
     series2.add(1.0, 440.0);
     series2.add(2.0, 500.0);
     series2.add(3.0, 560.0);
     series2.add(4.0, 720.0);
     series2.add(5.0, 780.0);
     series2.add(6.0, 840.0);
     series2.add(7.0, 900.0);
     series2.add(8.0, 960.0);*/
    final XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series1);
    if (ShowTargetHP.isSelected()) {
        dataset.addSeries(series2);
    }

    return dataset;

}