Example usage for org.jfree.data.xy DefaultXYDataset DefaultXYDataset

List of usage examples for org.jfree.data.xy DefaultXYDataset DefaultXYDataset

Introduction

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

Prototype

public DefaultXYDataset() 

Source Link

Document

Creates a new DefaultXYDataset instance, initially containing no data.

Usage

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

/**
 * Some tests for the addSeries() method.
 *//* ww w  .jav a  2s. c om*/
public void testAddSeries() {
    DefaultXYDataset d = new DefaultXYDataset();
    d.addSeries("S1", new double[][] { { 1.0 }, { 2.0 } });
    assertEquals(1, d.getSeriesCount());
    assertEquals("S1", d.getSeriesKey(0));

    // check that adding a series will overwrite the old series
    d.addSeries("S1", new double[][] { { 11.0 }, { 12.0 } });
    assertEquals(1, d.getSeriesCount());
    assertEquals(12.0, d.getYValue(0, 0), EPSILON);

    // check null key
    boolean pass = false;
    try {
        d.addSeries(null, new double[][] { { 1.0 }, { 2.0 } });
    } catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}

From source file:SciTK.PlotXY.java

/** 
* Constructor for a multiple sets of data 
*
* @param data_in the data to plot. m x n x 2 size, eg data_in[0][i] = [x_i,y_i]; m data sets of n points.
* @param name the data set's names in a String array of length m
* @param x_label the label for the abscissa
* @param y_label the label for the ordinate
* @param window_title a label for the window title
*//*from ww w.  j a va 2s .c om*/
public PlotXY(double[][][] data_in, String name[], String x_label, String y_label, String window_title) {
    data = new DefaultXYDataset();
    // iterate over input data sets:
    for (int i = 0; i < data_in.length; i++) {
        data.addSeries(name[i], data_in[i]);
    }

    // common routine:
    init(x_label, y_label, window_title);
}

From source file:org.matsim.pt.counts.PtCountsSimRealPerHourGraph.java

/**
 * @param hour/* w  w w  .ja v  a  2s. c  o  m*/
 *            A value in 1..24, 1 for 0 a.m. to 1 a.m., 2 for 1 a.m. to 2
 *            a.m. ...
 */
@Override
public JFreeChart createChart(final int hour) {
    this.hour = hour;

    XYSeriesCollection dataset0 = new XYSeriesCollection();
    XYSeries series = new XYSeries("MATSim volumes");
    // easier to use another dataset
    XYSeriesCollection dataset_outliers = new XYSeriesCollection();
    XYSeries series_outliers = new XYSeries("MATSim outliers");

    CustomXYURLGenerator url_gen = new CustomXYURLGenerator();
    CustomXYToolTipGenerator tt_gen = new CustomXYToolTipGenerator();

    final ArrayList<String> urls = new ArrayList<String>();
    final ArrayList<String> tooltips = new ArrayList<String>();
    List<Comp> comps = new Vector<Comp>();

    Iterator<CountSimComparison> l_it = this.ccl_.iterator();
    // int elementCounter=0;
    while (l_it.hasNext()) {
        CountSimComparison cc = l_it.next();

        /*
         * values with simVal==0.0 or countVal==0.0 are drawn on the x==1
         * or/and y==1-line Such values are the result of a poor simulation
         * run, but they can also represent a valid result (closing summer
         * road during winter time)
         */
        if (cc.getHour() == hour) {
            // elementCounter++;
            double realVal = 1.0;
            double simVal = 1.0;
            if (cc.getCountValue() > 0.0 && cc.getSimulationValue() > 0.0) {
                realVal = cc.getCountValue();
                simVal = cc.getSimulationValue();
                series.add(realVal, simVal);
                comps.add(new Comp(realVal, "link" + cc.getId() + ".html",
                        "Link " + cc.getId() + "; " + "Count: " + realVal + ", Sim: " + simVal));
            } else {
                realVal = Math.max(1.0, cc.getCountValue());
                simVal = Math.max(1.0, cc.getSimulationValue());
                series_outliers.add(realVal, simVal);
            }

        } // if
    } // while
    dataset0.addSeries(series);
    dataset_outliers.addSeries(series_outliers);

    /*
     * first we have to sort the vector according to the rendering ordering
     * (which is the x value). REALLY??? After hours of searching no better
     * solution found! please help!
     */

    Collections.sort(comps, new MyComparator());

    for (Iterator<Comp> iter = comps.iterator(); iter.hasNext();) {
        Comp cp = iter.next();
        urls.add(cp.getURL());
        tooltips.add(cp.getTooltip());
    }

    url_gen.addURLSeries(urls);
    tt_gen.addToolTipSeries(tooltips);

    String title = "[" + this.countsType + "]\tVolumes " + (hour - 1) + ":00 - " + (hour) + ":00, Iteration: "
            + this.iteration_;
    this.setChartTitle(title);
    this.chart_ = ChartFactory.createXYLineChart(title, "Count Volumes [veh/h]", // x axis label
            "Sim Volumes [veh/h]", // y axis label
            dataset0, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            true // urls
    );
    XYPlot plot = this.chart_.getXYPlot();
    final LogarithmicAxis axis_x = new LogarithmicAxis("Count Volumes [veh/h]");
    final LogarithmicAxis axis_y = new LogarithmicAxis("Sim Volumes [veh/h]");
    axis_x.setAllowNegativesFlag(false);
    axis_y.setAllowNegativesFlag(false);

    // regular values
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setLinesVisible(false);
    renderer.setURLGenerator(url_gen);
    renderer.setSeriesPaint(0, Color.black);
    renderer.setSeriesToolTipGenerator(0, tt_gen);
    renderer.setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0));

    // outliers
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    renderer2.setLinesVisible(false);
    renderer2.setSeriesPaint(0, Color.red);
    renderer2.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0));

    // error band
    DefaultXYDataset dataset1 = new DefaultXYDataset();
    dataset1.addSeries("f1x", new double[][] { { 1.0, 10000.0 }, { 1.0, 10000.0 } });
    dataset1.addSeries("f2x", new double[][] { { 1.0, 10000.0 }, { 2.0, 20000.0 } });
    dataset1.addSeries("f05x", new double[][] { { 2.0, 10000.0 }, { 1.0, 5000.0 } });

    XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer();
    renderer3.setShapesVisible(false);
    renderer3.setSeriesPaint(0, Color.blue);
    renderer3.setSeriesPaint(1, Color.blue);
    renderer3.setSeriesPaint(2, Color.blue);
    renderer3.setBaseSeriesVisibleInLegend(false);
    renderer3.setSeriesItemLabelsVisible(0, true);
    renderer3.setSeriesItemLabelsVisible(1, false);
    renderer3.setSeriesItemLabelsVisible(2, false);

    XYTextAnnotation annotation0 = new XYTextAnnotation("2.0 count", 12000.0, 15500.0);
    annotation0.setFont(new Font("SansSerif", Font.BOLD, 11));
    plot.addAnnotation(annotation0);
    XYTextAnnotation annotation1 = new XYTextAnnotation("count", 13000.0, 10000.0);
    annotation1.setFont(new Font("SansSerif", Font.BOLD, 11));
    plot.addAnnotation(annotation1);
    XYTextAnnotation annotation2 = new XYTextAnnotation("0.5 count", 11000.0, 3500.0);
    annotation2.setFont(new Font("SansSerif", Font.BOLD, 11));
    plot.addAnnotation(annotation2);

    plot.setDomainAxis(axis_x);
    plot.setRangeAxis(axis_y);
    plot.setRenderer(0, renderer);

    plot.setRenderer(1, renderer2);
    plot.setDataset(1, dataset_outliers);

    plot.setRenderer(2, renderer3);
    plot.setDataset(2, dataset1);

    plot.getRangeAxis().setRange(1.0, 19000.0);
    plot.getDomainAxis().setRange(1.0, 19000.0);

    return this.chart_;
}

From source file:SciTK.PlotXYLine.java

/** Constructor for multiple sets of data
 * @param data_in the data to plot. m x n x 2 size, eg data_in[0][i] = [x_i,y_i]; m data sets of n points.
 * @param name the data set's names in a String array
 * @param x_label the label for the abscissa
 * @param y_label the label for the ordinate
 * @param window_title a label for the window title
*//*from  w w  w  . j av  a 2  s  .  co m*/
public PlotXYLine(double[][][] data_in, String name[], String x_label, String y_label, String window_title) {
    // set up the data set:
    data = new DefaultXYDataset();
    // iterate over input data sets:
    for (int i = 0; i < data_in.length; i++) {
        data.addSeries(name[i], data_in[i]);
    }

    init(x_label, y_label, window_title);
}

From source file:org.matsim.pt.counts.obsolete.PtCountsSimRealPerHourGraph.java

/**
 * @param hour//from w  ww.j  a v a 2  s  . co  m
 *            A value in 1..24, 1 for 0 a.m. to 1 a.m., 2 for 1 a.m. to 2
 *            a.m. ...
 */
@Override
@Deprecated // use standard counts package
public JFreeChart createChart(final int hour) {
    this.hour = hour;

    XYSeriesCollection dataset0 = new XYSeriesCollection();
    XYSeries series = new XYSeries("MATSim volumes");
    // easier to use another dataset
    XYSeriesCollection dataset_outliers = new XYSeriesCollection();
    XYSeries series_outliers = new XYSeries("MATSim outliers");

    CustomXYURLGenerator url_gen = new CustomXYURLGenerator();
    CustomXYToolTipGenerator tt_gen = new CustomXYToolTipGenerator();

    final ArrayList<String> urls = new ArrayList<String>();
    final ArrayList<String> tooltips = new ArrayList<String>();
    List<Comp> comps = new Vector<Comp>();

    Iterator<CountSimComparison> l_it = this.ccl_.iterator();
    // int elementCounter=0;
    while (l_it.hasNext()) {
        CountSimComparison cc = l_it.next();

        /*
         * values with simVal==0.0 or countVal==0.0 are drawn on the x==1
         * or/and y==1-line Such values are the result of a poor simulation
         * run, but they can also represent a valid result (closing summer
         * road during winter time)
         */
        if (cc.getHour() == hour) {
            // elementCounter++;
            double realVal = 1.0;
            double simVal = 1.0;
            if (cc.getCountValue() > 0.0 && cc.getSimulationValue() > 0.0) {
                realVal = cc.getCountValue();
                simVal = cc.getSimulationValue();
                series.add(realVal, simVal);
                comps.add(new Comp(realVal, "link" + cc.getId() + ".html",
                        "Link " + cc.getId() + "; " + "Count: " + realVal + ", Sim: " + simVal));
            } else {
                realVal = Math.max(1.0, cc.getCountValue());
                simVal = Math.max(1.0, cc.getSimulationValue());
                series_outliers.add(realVal, simVal);
            }

        } // if
    } // while
    dataset0.addSeries(series);
    dataset_outliers.addSeries(series_outliers);

    /*
     * first we have to sort the vector according to the rendering ordering
     * (which is the x value). REALLY??? After hours of searching no better
     * solution found! please help!
     */

    Collections.sort(comps, new MyComparator());

    for (Iterator<Comp> iter = comps.iterator(); iter.hasNext();) {
        Comp cp = iter.next();
        urls.add(cp.getURL());
        tooltips.add(cp.getTooltip());
    }

    url_gen.addURLSeries(urls);
    tt_gen.addToolTipSeries(tooltips);

    String title = "[" + this.countsType + "]\tVolumes " + (hour - 1) + ":00 - " + (hour) + ":00, Iteration: "
            + this.iteration_;
    this.setChartTitle(title);
    this.chart_ = ChartFactory.createXYLineChart(title, "Count Volumes [veh/h]", // x axis label
            "Sim Volumes [veh/h]", // y axis label
            dataset0, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            true // urls
    );
    XYPlot plot = this.chart_.getXYPlot();
    final LogarithmicAxis axis_x = new LogarithmicAxis("Count Volumes [veh/h]");
    final LogarithmicAxis axis_y = new LogarithmicAxis("Sim Volumes [veh/h]");
    axis_x.setAllowNegativesFlag(false);
    axis_y.setAllowNegativesFlag(false);

    // regular values
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setLinesVisible(false);
    renderer.setURLGenerator(url_gen);
    renderer.setSeriesPaint(0, Color.black);
    renderer.setSeriesToolTipGenerator(0, tt_gen);
    renderer.setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0));

    // outliers
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    renderer2.setLinesVisible(false);
    renderer2.setSeriesPaint(0, Color.red);
    renderer2.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0));

    // error band
    DefaultXYDataset dataset1 = new DefaultXYDataset();
    dataset1.addSeries("f1x", new double[][] { { 1.0, 10000.0 }, { 1.0, 10000.0 } });
    dataset1.addSeries("f2x", new double[][] { { 1.0, 10000.0 }, { 2.0, 20000.0 } });
    dataset1.addSeries("f05x", new double[][] { { 2.0, 10000.0 }, { 1.0, 5000.0 } });

    XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer();
    renderer3.setShapesVisible(false);
    renderer3.setSeriesPaint(0, Color.blue);
    renderer3.setSeriesPaint(1, Color.blue);
    renderer3.setSeriesPaint(2, Color.blue);
    renderer3.setBaseSeriesVisibleInLegend(false);
    renderer3.setSeriesItemLabelsVisible(0, true);
    renderer3.setSeriesItemLabelsVisible(1, false);
    renderer3.setSeriesItemLabelsVisible(2, false);

    XYTextAnnotation annotation0 = new XYTextAnnotation("2.0 count", 12000.0, 15500.0);
    annotation0.setFont(new Font("SansSerif", Font.BOLD, 11));
    plot.addAnnotation(annotation0);
    XYTextAnnotation annotation1 = new XYTextAnnotation("count", 13000.0, 10000.0);
    annotation1.setFont(new Font("SansSerif", Font.BOLD, 11));
    plot.addAnnotation(annotation1);
    XYTextAnnotation annotation2 = new XYTextAnnotation("0.5 count", 11000.0, 3500.0);
    annotation2.setFont(new Font("SansSerif", Font.BOLD, 11));
    plot.addAnnotation(annotation2);

    plot.setDomainAxis(axis_x);
    plot.setRangeAxis(axis_y);
    plot.setRenderer(0, renderer);

    plot.setRenderer(1, renderer2);
    plot.setDataset(1, dataset_outliers);

    plot.setRenderer(2, renderer3);
    plot.setDataset(2, dataset1);

    plot.getRangeAxis().setRange(1.0, 19000.0);
    plot.getDomainAxis().setRange(1.0, 19000.0);

    return this.chart_;
}

From source file:com.bt.aloha.sipstone.GenGraph.java

private XYDataset createDataset_TotalCallCreated_AvgResponseTime() {
    DefaultXYDataset dataSet = new DefaultXYDataset();
    final String ART = "AvgRT";
    List<Double> calls = data.get("TotalCallCreated");
    List<Double> respTime = data.get("ResponseTime1(C)");
    double[] callsArray = new double[calls.size()];
    double[] respTimeArray = new double[calls.size()];
    for (int i = 0; i < calls.size(); i++) {
        callsArray[i] = calls.get(i).doubleValue();
        respTimeArray[i] = respTime.get(i).doubleValue();
    }/*from w  w  w.jav a  2 s . c o  m*/
    dataSet.addSeries(ART, new double[][] { callsArray, respTimeArray });
    double[] limitArray = new double[2];
    limitArray[0] = 200;
    limitArray[1] = 200;
    double[] callsLimitArray = new double[2];
    callsLimitArray[0] = callsArray[0];
    callsLimitArray[1] = callsArray[callsArray.length - 1];
    dataSet.addSeries("ARTLimit", new double[][] { callsLimitArray, limitArray });
    return dataSet;
}

From source file:org.jax.maanova.fit.gui.ResidualPlotPanel.java

private void updateDataPoints() {
    this.cachedXYData = null;
    XYProbeData[] xyData = this.getXYData();

    DefaultXYDataset xyDataSet = new DefaultXYDataset();
    for (int arrayIndex = 0; arrayIndex < xyData.length; arrayIndex++) {
        XYProbeData currData = xyData[arrayIndex];
        xyDataSet.addSeries(arrayIndex, new double[][] { currData.getXData(), currData.getYData() });
    }//from   w  ww . jav  a2  s .  c o  m

    JFreeChart scatterPlot = ChartFactory.createScatterPlot(this.chartConfigurationDialog.getChartTitle(),
            this.chartConfigurationDialog.getXAxisLabel(), this.chartConfigurationDialog.getYAxisLabel(),
            xyDataSet, PlotOrientation.VERTICAL, false, false, false);

    XYPlot xyPlot = (XYPlot) scatterPlot.getPlot();
    xyPlot.setRenderer(PlotUtil.createMonochromeScatterPlotRenderer());
    if (this.viewArea != null) {
        PlotUtil.rescaleXYPlot(this.viewArea, xyPlot);
    }

    this.saveGraphImageAction.setChart(scatterPlot);
    this.chartPanel.setChart(scatterPlot);
}

From source file:SciTK.PlotXYStep.java

/** Constructor for multipe sets of data 
 * @param data_in the data to plot. m x n x 2 size, eg data_in[0][i] = [x_i,y_i]; m data sets of n points.
 * @param name the data set's names in a String array
 * @param x_label the label for the abscissa
 * @param y_label the label for the ordinate
 * @param window_title a label for the window title
*//* w w  w.  java2 s.c o  m*/
public PlotXYStep(double[][][] data_in, String name[], String x_label, String y_label, String window_title) {
    data = new DefaultXYDataset();
    // iterate over input data sets:
    for (int i = 0; i < data_in.length; i++) {
        data.addSeries(name[i], data_in[i]);
    }

    // Step Chart requires some hand-holding for the horizontal (domain) axis
    double x_min = 0;
    double x_max = 0;
    for (int i = 0; i < data_in.length; i++) {
        for (int j = 0; j < data_in[i].length; j++) {
            if (data_in[i][j][0] < x_min)
                x_min = data_in[i][j][0];
            else if (data_in[i][j][0] > x_max)
                x_max = data_in[i][j][0];
        }
    }

    // call common init routine:
    init(x_label, y_label, window_title, x_min, x_max);
}

From source file:edu.cmu.sv.modelinference.eventtool.EventVisualizer.java

private void visualizeClasses(ClassificationResult classes, Map<EventClass, Color> clusterColors) {
    DataChart clustersDataChart = new DataChart("Classification chart");
    JFreeChart clusterChart = clustersDataChart.chart("");
    XYPlot clusterPlot = clusterChart.getXYPlot();

    int dataSetIndex = 0;
    Map<Integer, EventClass> dataSetIdx2EvtClass = new HashMap<>(); //ugly
    DefaultXYDataset eventDataSet = new DefaultXYDataset();
    for (EventClass evtCl : classes.getEventClasses()) {
        double[][] clusterDataSet = new double[][] { new double[evtCl.getEvents().size()],
                new double[evtCl.getEvents().size()] };
        int i = 0;
        for (Event data : evtCl.getEvents()) {
            clusterDataSet[0][i] = 0;//from  ww  w. j  a v a2  s .  co m
            clusterDataSet[1][i] = data.getFeature().getData();
            i++;
        }
        eventDataSet.addSeries("Class " + evtCl.getClassId(), clusterDataSet);

        dataSetIdx2EvtClass.put(dataSetIndex, evtCl);
        dataSetIndex++;
    }
    clusterPlot.setDataset(eventDataSet);

    for (Entry<Integer, EventClass> ent : dataSetIdx2EvtClass.entrySet()) {
        int idx = ent.getKey();
        Color clr = clusterColors.get(ent.getValue());
        logger.info("Setting color " + clr + " for event class " + ent.getValue().getClassId() + " with index "
                + idx);
        clusterPlot.getRendererForDataset(clusterPlot.getDataset(0)).setSeriesPaint(idx, clr);
    }

    clustersDataChart.pack();
    RefineryUtilities.centerFrameOnScreen(clustersDataChart);
    clustersDataChart.setVisible(true);
}

From source file:net.bioclipse.chart.ChartUtils.java

/**
 * Plot time series//from   w w  w  .  ja  v  a  2 s. c o m
 * 
 * @param dataValues
 * @param timeValues
 * @param xLabel X axis label
 * @param yLabel Y axis label
 * @param title Chart title
 * @param dataSource 
 * @param indices 
 */
public static void timeSeries(double[] dataValues, double[] timeValues, String xLabel, String yLabel,
        String title, int[] indices, IEditorPart dataSource) {
    setupData(dataValues, timeValues, xLabel, yLabel, title);
    DefaultXYDataset dataset = new DefaultXYDataset();
    dataset.addSeries(1, values);
    chart = ChartFactory.createTimeSeriesChart(title, xLabel, yLabel, (XYDataset) dataset, false, false, false);

    ChartDescriptor descriptor = new ChartDescriptor(dataSource, indices, ChartConstants.TIME_SERIES, xLabel,
            yLabel);
    chartManager.put(chart, descriptor);

    view.display(chart);
    ChartUtils.currentPlotType = ChartConstants.TIME_SERIES;
}