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:AirplaneSettings.java

public void planeGraph(List<Double> gp, List<Double> pp) {
    // Create XY series for the ground
    XYSeries ground = new XYSeries("Ground Height");
    for (int i = 0; i < gp.size(); i++)
        ground.add(i, gp.get(i));/*from   w w  w . ja  va 2 s .c  o m*/

    // Create XY series for the plane
    XYSeries plane = new XYSeries("Plane Height");
    for (int i = 0; i < pp.size(); i++)
        plane.add(i, pp.get(i));

    // Add the series to the data set
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(ground);
    dataset.addSeries(plane);

    // Generate the graph
    JFreeChart memFunction = ChartFactory.createXYLineChart("Plane Flight", // Title
            "Time", // x-axis Label
            "Height", // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );

    ChartFrame frame = new ChartFrame("Plane Flight", memFunction);
    frame.pack();
    frame.setVisible(true);
}

From source file:researchbehaviour.ChangePanel.java

private XYDataset createDataset() throws IOException {

    XYSeries series1 = new XYSeries("Default");
    series1.add(1, 57.87);/*from w  w  w . ja v a2 s  .  c o  m*/
    series1.add(2, 59.842);
    series1.add(3, 68.5);
    series1.add(4, 74.625);
    series1.add(5, 79.235);

    ChangeValues cvv = new ChangeValues();

    ArrayList<Double> updateVal1 = new ArrayList<Double>();
    updateVal1 = cvv.changedCutOff();

    XYSeries series2 = new XYSeries("Current");
    series2.add(1, updateVal1.get(0));
    series2.add(2, updateVal1.get(1));
    series2.add(3, updateVal1.get(2));
    series2.add(4, updateVal1.get(3));
    series2.add(5, updateVal1.get(4));

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

    return dataset;
}

From source file:sistemacontrole.LeituraEscritaCanais.java

public XYDataset createDatasetEntrada() {
    try {/*w  ww. j  a  va  2  s . c o m*/
        Thread.sleep(100);
    } catch (InterruptedException ex) {
        System.out.println("createDatasetEntrada() exception: " + ex);
    }

    final XYSeriesCollection dataset = new XYSeriesCollection();
    for (int i = 0; i < 7; ++i) {
        if (this.canaisSelecionados[i]) {
            dataset.addSeries(this.sinal_entrada[i]);
        }
    }
    dataset.addSeries(this.setPointCurva);
    return dataset;
}

From source file:umontreal.iro.lecuyer.charts.YListSeriesCollection.java

/**
 * Creates a new <TT>YListSeriesCollection</TT> instance with default
 *    parameters and given data series. The matrix <TT>data</TT> represents a
 *    set of plotting data. More specifically, each row of <TT>data</TT>
 *    represents a <SPAN CLASS="MATH"><I>y</I></SPAN>-coordinates set.
 *    Position in the vector will form the <SPAN CLASS="MATH"><I>x</I></SPAN>-coordinates. Indeed, for each serie
 *    <SPAN CLASS="MATH"><I>i</I></SPAN>, the value <TT>data</TT><SPAN CLASS="MATH">[<I>i</I>][<I>j</I>]</SPAN> corresponds to the point
 *    //from   w  w w  . j a va2 s . c om
 * <SPAN CLASS="MATH">(<I>j</I> + 1,<TT>data</TT>[<I>j</I>])</SPAN> on the chart.
 *   However, only <SPAN  CLASS="textit">the first</SPAN> <TT>numPoints</TT> of <TT>data</TT> will
 *   be considered for each series of points.
 * 
 * @param data series of point sets.
 * 
 *    @param numPoints Number of points to plot
 * 
 */
public YListSeriesCollection(double[][] data, int numPoints) {
    renderer = new XYLineAndShapeRenderer(true, false);
    seriesCollection = new XYSeriesCollection();

    XYSeriesCollection tempSeriesCollection = (XYSeriesCollection) seriesCollection;
    for (int i = 0; i < data.length; i++) {
        XYSeries serie = new XYSeries(" ");
        for (int j = 0; j < numPoints; j++)
            serie.add(j + 1, data[i][j]);
        tempSeriesCollection.addSeries(serie);
    }

    final int s = tempSeriesCollection.getSeriesCount();

    // set default colors
    for (int i = 0; i < s; i++) {
        renderer.setSeriesPaint(i, getDefaultColor(i));
    }

    // set default plot style
    plotStyle = new String[s];
    marksType = new String[s];
    dashPattern = new String[s];
    for (int i = 0; i < s; i++) {
        marksType[i] = " ";
        plotStyle[i] = "smooth";
        dashPattern[i] = "solid";
    }
}

From source file:org.azrul.langmera.LineChart.java

/**
 * Creates a sample dataset.//from  w  w w  .j a  va  2  s  .com
 *
 * @return a sample dataset.
 */
public XYDataset createDataset(Map<String, List<Double>> dataList) {
    final XYSeriesCollection dataset = new XYSeriesCollection();
    for (String key : dataList.keySet()) {
        final XYSeries series = new XYSeries(key);
        int maxT = dataList.get(key).size();
        for (int j = 0; j < (maxT - 1); j++) {
            Double v = dataList.get(key).get(j) * 100.0;
            series.add((double) j, (double) (v));
        }
        dataset.addSeries(series);
    }
    return dataset;

}

From source file:playground.artemc.socialCost.MeanTravelTimeWriter.java

/**
 * @return a graphic showing the number of agents in the evacuated area
 *//*from   www . j a v a2 s .  c o m*/
private JFreeChart getGraphic(String[] modeNames, double data[][]) {

    final XYSeriesCollection xyData = new XYSeriesCollection();

    for (int j = 0; j < modeNames.length; j++) {
        String modeName = modeNames[j];
        double[] d = data[j];

        XYSeries dataSerie = new XYSeries(modeName, false, true);

        for (int i = 0; i < d.length; i++) {
            dataSerie.add(i, d[i]);
        }

        xyData.addSeries(dataSerie);
    }

    //      final JFreeChart chart = ChartFactory.createXYStepChart(
    final JFreeChart chart = ChartFactory.createXYLineChart("mean trip travel time, all transport modes modes",
            "iteration", "travel time", xyData, PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));
    return chart;
}

From source file:org.jfree.data.xy.junit.XYSeriesCollectionTest.java

/**
 * A test for bug report 1170825.//from   www  . ja v  a 2s. c o  m
 */
public void test1170825() {
    XYSeries s1 = new XYSeries("Series1");
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(s1);
    try {
        /* XYSeries s = */ dataset.getSeries(1);
    } catch (IllegalArgumentException e) {
        // correct outcome
    } catch (IndexOutOfBoundsException e) {
        assertTrue(false); // wrong outcome
    }
}

From source file:org.jfree.data.xy.junit.XYSeriesCollectionTest.java

/**
 * A check that the dataset prevents renaming a series to the name of an 
 * existing series in the dataset./*  ww  w  .  j a  v  a  2s.  co m*/
 */
public void testRenameSeries() {
    XYSeries s1 = new XYSeries("S1");
    XYSeries s2 = new XYSeries("S2");
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(s1);
    dataset.addSeries(s2);
    boolean pass = false;
    try {
        s2.setKey("S1");
    } catch (RuntimeException e) {
        pass = true;
    }
    assertTrue(pass);
}

From source file:edu.pdi2.visual.ThresholdSignature.java

private void plot() {
    if (signature != null) {
        XYSeries signature1 = new XYSeries("Original");
        XYSeries signature2 = new XYSeries("Max");
        XYSeries signature3 = new XYSeries("Min");
        double aux = 0;
        for (int i = 0; i < signature.length; i++) {
            signature1.add(i + 1, signature[i]);
        }/*  w  ww  . j  a v a2s .c  o m*/
        for (int i = 0; i < signature.length; i++) {
            aux = signature[i] + banda[i];
            if (aux > 255)
                aux = 255;
            signature2.add(i + 1, aux);
        }
        for (int i = 0; i < signature.length; i++) {
            aux = signature[i] - banda[i];
            if (aux < 0)
                aux = 0;
            signature3.add(i + 1, aux);
        }

        XYSeriesCollection dataset = new XYSeriesCollection();
        dataset.addSeries(signature1);
        dataset.addSeries(signature2);
        dataset.addSeries(signature3);
        XYPlot plot = (XYPlot) signatureG.getPlot();
        plot.setDataset(dataset);
    }
}

From source file:org.jfree.data.xy.junit.XYSeriesCollectionTest.java

/**
 * Confirm that cloning works.//from w w  w. j a va  2  s.co m
 */
public void testCloning() {
    XYSeries s1 = new XYSeries("Series");
    s1.add(1.0, 1.1);
    XYSeriesCollection c1 = new XYSeriesCollection();
    c1.addSeries(s1);
    XYSeriesCollection c2 = null;
    try {
        c2 = (XYSeriesCollection) c1.clone();
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
        assertTrue(false);
        return;
    }
    assertTrue(c1 != c2);
    assertTrue(c1.getClass() == c2.getClass());
    assertTrue(c1.equals(c2));

    // check independence
    s1.setDescription("XYZ");
    assertFalse(c1.equals(c2));
}