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:projects.hip.exec.HrDiagram.java

/**
 * Plot the distribution of distance of all objects.
 * @param d_hist//from ww w . ja  va 2  s  . co  m
 *    The array containing the distance distribution histogram.
 * @return
 *    A {@link JFreeChart} containing the plot.
 */
private static JFreeChart getDistanceChart(double[] d_hist) {

    XYSeries series = new XYSeries("Distance distribution");

    for (int i = 0; i < d_hist.length; i++) {
        // Centre of this distance bin
        double d = d_min + i * d_step + d_step / 2.0;
        series.add(d, d_hist[i]);
    }
    XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(series);

    // Set up the renderer
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, false);

    // Configure axes
    NumberAxis xAxis = new NumberAxis("Distance [pc]");
    xAxis.setRange(d_min, d_max);

    NumberAxis yAxis = new NumberAxis("Number of objects");
    yAxis.setAutoRangeIncludesZero(true);

    // Configure plot
    XYPlot xyplot = new XYPlot(data, xAxis, yAxis, renderer);
    xyplot.setBackgroundPaint(Color.white);

    JFreeChart dChart = new JFreeChart("Distance distribution of Hipparcos stars", xyplot);
    dChart.removeLegend();
    dChart.setBackgroundPaint(Color.white);

    return dChart;
}

From source file:eu.choreos.vv.chart.XYChart.java

private static void createDataset(XYSeriesCollection dataset, LineData report) {
    XYSeries series = new XYSeries(report.getName());
    //       for (int i = 0; i < report.size(); i++) {
    for (Double x : report.keySet()) {
        series.add(x, report.get(x));/*from   w  w  w  . j  av  a 2s .  com*/
    }
    dataset.addSeries(series);
}

From source file:org.physionet.graphics.Plot.java

public static XYDataset createDataset(ArrayList[] data) {
    //XYDataset result = DatasetUtilities.sampleFunction2D(new X2(),
    //        -4.0, 4.0, 40, "f(x)");
    XYSeriesCollection result = new XYSeriesCollection();
    XYSeries series = new XYSeries(1);
    //Insert data into plotting series 
    for (int n = 0; n < data[1].size(); n++) {
        series.add(Double.valueOf((String) data[0].get(n)), Double.valueOf((String) data[1].get(n)));
    }//from  w  w  w.  ja va 2  s  .  c om
    result.addSeries(series);
    return result;
}

From source file:dumbara.view.Chart1.java

public static void ViewLineChart(String[] agencyID, String[] sslesDate, ArrayList<String[]> arrayList)
        throws SQLException, ClassNotFoundException {
    XYSeries series1 = new XYSeries("Agency 1");
    XYSeries series2 = new XYSeries("Agency 2");
    XYSeries series3 = new XYSeries("Agency 3");
    XYSeries series4 = new XYSeries("Agency 4");

    for (String[] strings : arrayList) {

        for (int i = 0; i < sslesDate.length; i++) {
            System.out.println(sslesDate[i].split("-")[1] + "");
            series1.add(Double.parseDouble(sslesDate[i].split("-")[1] + ""),
                    Double.parseDouble(arrayList.get(0)[i]));
        }//from   w  w  w  . j  av a  2 s.  co  m

        for (int i = 0; i < sslesDate.length; i++) {
            series2.add(Double.parseDouble(sslesDate[i].split("-")[1] + ""),
                    Double.parseDouble(arrayList.get(1)[i]));
        }

        for (int i = 0; i < sslesDate.length; i++) {
            series3.add(Double.parseDouble(sslesDate[i].split("-")[1] + ""),
                    Double.parseDouble(arrayList.get(2)[i]));
        }

        for (int i = 0; i < sslesDate.length; i++) {
            series4.add(Double.parseDouble(sslesDate[i].split("-")[1] + ""),
                    Double.parseDouble(arrayList.get(3)[i]));

        }

    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series1);
    dataset.addSeries(series2);
    dataset.addSeries(series3);
    dataset.addSeries(series4);
    XYDataset dataset1 = dataset;
    JFreeChart chart = ChartFactory.createXYLineChart("", "Test Id", "Average Marks", dataset1,
            PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesLinesVisible(1, true);
    renderer.setSeriesShapesVisible(1, true);
    renderer.setSeriesLinesVisible(2, true);
    renderer.setSeriesShapesVisible(2, true);
    renderer.setSeriesFillPaint(2, Color.MAGENTA);
    plot.setRenderer(renderer);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 300));
    //(chartPanel);
    ChartFrame frame = new ChartFrame("Dumbara Water Management System", chart);
    frame.setLocationRelativeTo(null);
    frame.pack();
    frame.setVisible(true);

}

From source file:es.bsc.autonomic.powermodeller.graphics.TotalPowerVsTotalPrediction.java

private static XYDataset dataSetToJFreeChartXYDataSet(DataSet ds) {

    XYSeriesCollection xyseriescollection = new XYSeriesCollection();

    for (String metric : ds.getHeader()) {
        List<Double> column = ds.getCol(metric);
        XYSeries xyseries = new XYSeries(metric);
        for (int i = 0; i < column.size(); i++) {
            xyseries.add(i, column.get(i));
        }/*from   ww w  .j  a  v  a2s  . co m*/
        xyseriescollection.addSeries(xyseries);
    }

    return xyseriescollection;
}

From source file:edu.msu.cme.rdp.rarefaction.RarefactionPlotter.java

private static void plotToFile(List<RarefactionResult> resultsToPlot, int numSeqs, String title,
        File outputFile) throws IOException {
    XYSeriesCollection dataset = new XYSeriesCollection();

    for (RarefactionResult result : resultsToPlot) {
        XYSeries series = new XYSeries(RarefactionWriter.dformat.format(result.distance) + " distance");

        for (int plotIndex : RarefactionWriter.getIndiciesToPlot(numSeqs)) {
            series.add(result.geteArray()[plotIndex], plotIndex);
        }//from   ww  w  .ja v  a2  s .c o  m

        dataset.addSeries(series);
    }

    JFreeChart chart = ChartFactory.createXYLineChart(title, "", "", dataset, PlotOrientation.HORIZONTAL, true,
            false, false);
    ChartUtilities.saveChartAsPNG(outputFile, chart, 1280, 1024);
}

From source file:org.jfree.chart.demo.NormalDistributionDemo2.java

public static XYDataset createDataset() {
    XYSeriesCollection xyseriescollection = new XYSeriesCollection();
    NormalDistributionFunction2D normaldistributionfunction2d = new NormalDistributionFunction2D(0.0D, 1.0D);
    org.jfree.data.xy.XYSeries xyseries = DatasetUtilities.sampleFunction2DToSeries(
            normaldistributionfunction2d, -5.0999999999999996D, 5.0999999999999996D, 121, "N1");
    xyseriescollection.addSeries(xyseries);
    NormalDistributionFunction2D normaldistributionfunction2d1 = new NormalDistributionFunction2D(0.0D,
            Math.sqrt(0.20000000000000001D));
    org.jfree.data.xy.XYSeries xyseries1 = DatasetUtilities.sampleFunction2DToSeries(
            normaldistributionfunction2d1, -5.0999999999999996D, 5.0999999999999996D, 121, "N2");
    xyseriescollection.addSeries(xyseries1);
    NormalDistributionFunction2D normaldistributionfunction2d2 = new NormalDistributionFunction2D(0.0D,
            Math.sqrt(5D));// w  w  w.j  av  a  2  s.c o  m
    org.jfree.data.xy.XYSeries xyseries2 = DatasetUtilities.sampleFunction2DToSeries(
            normaldistributionfunction2d2, -5.0999999999999996D, 5.0999999999999996D, 121, "N3");
    xyseriescollection.addSeries(xyseries2);
    NormalDistributionFunction2D normaldistributionfunction2d3 = new NormalDistributionFunction2D(-2D,
            Math.sqrt(0.5D));
    org.jfree.data.xy.XYSeries xyseries3 = DatasetUtilities.sampleFunction2DToSeries(
            normaldistributionfunction2d3, -5.0999999999999996D, 5.0999999999999996D, 121, "N4");
    xyseriescollection.addSeries(xyseries3);
    return xyseriescollection;
}

From source file:org.encog.workbench.dialogs.activation.EquationPanel.java

/**
 * Creates a dataset with sample values from the normal distribution
 * function./*from   www  . j  av a  2 s.  c om*/
 *
 * @return A dataset.
 */
public static XYDataset createDataset(ActivationFunction activation, boolean normal) {
    XYSeriesCollection dataset = new XYSeriesCollection();

    if (normal) {
        Function2D n1 = new ActivationFunction2D(activation);// //new NormalDistributionFunction2D(0.0, 1.0);
        XYSeries s1 = DatasetUtilities.sampleFunction2DToSeries(n1, -5.1, 5.1, 121, "Activation Function");
        dataset.addSeries(s1);
    } else {
        if (activation.hasDerivative()) {
            Function2D n2 = new DerivativeFunction2D(activation);
            XYSeries s2 = DatasetUtilities.sampleFunction2DToSeries(n2, -5.1, 5.1, 121, "Derivative Function");
            dataset.addSeries(s2);
        }
    }

    return dataset;
}

From source file:flow.visibility.pcap.FlowProcess.java

/** function to create internal frame contain flow summary chart */

public static JInternalFrame FlowStatistic() {

    final StringBuilder errbuf = new StringBuilder(); // For any error msgs  
    final String file = "tmp-capture-file.pcap";

    //System.out.printf("Opening file for reading: %s%n", file);  

    /*************************************************************************** 
     * Second we open up the selected file using openOffline call 
     **************************************************************************/
    Pcap pcap = Pcap.openOffline(file, errbuf);

    if (pcap == null) {
        System.err.printf("Error while opening device for capture: " + errbuf.toString());
    }//from w ww.jav  a  2s  . c o  m

    Pcap pcap1 = Pcap.openOffline(file, errbuf);
    FlowMap map = new FlowMap();
    pcap1.loop(Pcap.LOOP_INFINITE, map, null);

    //System.out.printf(map.toString());
    //System.out.printf(map.toString2());

    /** Splitting the packets statistics strings from FlowMap function */

    String packet = map.toString2();
    String[] NumberPacket = packet.split(",");

    final XYSeries Flow = new XYSeries("Flow");

    for (int i = 0; i < NumberPacket.length - 1; i = i + 1) {

        //System.out.printf(NumberPacket[i+1] + "\n");
        double NoPacket = Double.valueOf(NumberPacket[i + 1]);
        Flow.add(i, NoPacket);

    }

    /** Create dataset for chart */

    final XYSeriesCollection dataset = new XYSeriesCollection();

    dataset.addSeries(Flow);

    /** Create the internal frame contain flow summary chart */

    JInternalFrame FlowStatistic = new JInternalFrame("Flow Statistic", true, true, true, true);
    FlowStatistic.setBounds(0, 0, 600, 330);

    ChartPanel chartPanel = new ChartPanel(createChart(dataset));
    chartPanel.setMouseZoomable(true, false);

    FlowStatistic.add(chartPanel);
    FlowStatistic.setVisible(true);
    FlowStatistic.revalidate();
    pcap1.close();

    return FlowStatistic;

}

From source file:stratego.neural.net.StrategoNeuralNet.java

private static void plotDataSet(List<NamedDataSet> ArraySetList, String network_name) {

    String plot_title = "Plot " + plotIndex + ": Overfitting on network " + network_name;
    XYSeriesCollection plotData = new XYSeriesCollection();

    for (NamedDataSet ns : ArraySetList) {
        XYSeries series = new XYSeries(ns.getName());
        double[] data = ns.getArray();
        for (int i = 0; i < data.length; i++) {
            series.add((double) i, data[i]);
        }/* w w w  .  j a  v  a 2 s. c o  m*/

        plotData.addSeries(series);
    }

    String title = plot_title;
    String xAxisLabel = "Epochs";
    String yAxisLabel = "Accuracy";
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    boolean legend = true; // might wanna set this to true at some point, but research the library
    boolean tooltips = false;
    boolean urls = false;
    JFreeChart chart = ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, plotData, orientation,
            legend, tooltips, urls);

    JPanel panel = new ChartPanel(chart);

    JFrame f = new JFrame();
    f.add(panel);
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.pack();
    f.setTitle(plot_title);

    f.setVisible(true);

    plotIndex++; // increase the plotindex
}