Example usage for org.jfree.data.xy XYSeries add

List of usage examples for org.jfree.data.xy XYSeries add

Introduction

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

Prototype

public void add(XYDataItem item, boolean notify) 

Source Link

Document

Adds a data item to the series and, if requested, sends a SeriesChangeEvent to all registered listeners.

Usage

From source file:playground.anhorni.crossborder.verification.TGZMCompare.java

public JFreeChart createChart(String actType) {

    XYSeriesCollection dataset0 = new XYSeriesCollection();
    XYSeries series0 = new XYSeries(actType + " Trips MATSim");
    XYSeries series1 = new XYSeries(actType + " Trips TGZM");

    for (int i = 0; i < 24; i++) {
        double realVal = this.aggregatedVolumePerHour[i];
        int calcVal = this.xTripsPerHour[i];
        series0.add(i, calcVal);
        series1.add(i, realVal);//from  www  .  j  a  v a2 s . c  om
    }
    dataset0.addSeries(series0);
    dataset0.addSeries(series1);

    String title = "Compare TGZM and MATSim volumes per hour";
    this.chart = ChartFactory.createXYLineChart(title, "hour", // x axis label
            "Trips", // y axis label
            dataset0, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    XYPlot plot = this.chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setLinesVisible(true);
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0));
    renderer.setSeriesPaint(1, Color.black);
    renderer.setSeriesShape(1, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0));

    plot.setRenderer(0, renderer);

    return this.chart;
}

From source file:carfuzzy.Operations.java

public JFreeChart setToChart(double input, double membership, XYSeries series, XYSeriesCollection collection,
        String x_axis) { // kurallari cizdirdikten sonra cizdir.

    series.add(input, membership);
    series.add(input, 0);/* www . j  a v a 2 s.  c o m*/
    series.add(0, membership);
    collection.addSeries(series);

    JFreeChart chart = XYGraph.drawChart(collection, x_axis, "Membership");
    XYPlot plot = chart.getXYPlot();
    XYItemRenderer renderer = plot.getRenderer();

    renderer.setSeriesStroke(collection.getSeriesCount() - 1, new BasicStroke(3.5f));
    renderer.setSeriesStroke(collection.getSeriesCount() - 1, new BasicStroke(3.5f));
    plot.setRenderer(renderer);
    return chart;
}

From source file:de.fhffm.jad.demo.view.LineChartPanel.java

/**
 * Add a value to one of the lines//w  w w . j  a va 2 s .  co  m
 * @param y
 * @param series
 */
public void addValue(double y, int series) {
    //Grab the line to add a value
    XYSeries current = null;
    if (series == 1) {
        current = series1;
    } else if (series == 2) {
        current = series2;
    } else {
        return;
    }
    current.remove(0);
    current.add(x, y);
}

From source file:web.diva.server.unused.ProfilePlotGenerator.java

/**
 *
 * @return dataset.//from w  w w  .jav a 2s.co m
 */
private XYDataset createDataset(Number[][] pointsData) {

    final XYSeriesCollection dataset = new XYSeriesCollection();

    for (int x = 0; x < pointsData.length; x++) {
        XYSeries series = new XYSeries(x);
        Number[] data = pointsData[x];
        for (int y = 0; y < data.length; y++) {
            series.add(y, data[y]);
        }

        dataset.addSeries(series);

    }
    return dataset;

}

From source file:playground.ivt.utils.TripModeShares.java

private void writePng() {
    final DefaultTableXYDataset dataset = new DefaultTableXYDataset();

    for (ModeHistory h : history.getHistories()) {
        final XYSeries series = new XYSeries(h.mode, false, false);

        for (int i : history.getIterations()) {
            series.add(i, h.getCount(i));
        }//from   ww w .jav a2 s .c o  m

        dataset.addSeries(series);
    }

    final ChartUtil chart = new WrapperChartUtil(
            ChartFactory.createStackedXYAreaChart("number of trips per mode", "iteration", "n trips", dataset,
                    PlotOrientation.VERTICAL, true, false, false));
    chart.addMatsimLogo();
    chart.saveAsPng(this.pngFileName, 800, 600);

}

From source file:com.griddynamics.jagger.reporting.chart.ChartHelper.java

public static Pair<String, XYSeriesCollection> adjustTime(XYSeriesCollection chartsCollection,
        Collection<IntervalMarker> markers) {
    int maxTime = 0;
    for (int i = 0; i < chartsCollection.getSeriesCount(); i++) {
        XYSeries series = chartsCollection.getSeries(i);
        for (int j = 0; j < series.getItemCount(); j++) {
            int x = series.getX(j).intValue();
            if (x > maxTime) {
                maxTime = x;/*from  ww  w.  j a  va2  s  . c om*/
            }
        }
    }

    String type = "ms";
    int div = 1;

    if (maxTime > 10 * 60 * 1000) {
        div = 60 * 1000;
        type = "min";
    }

    if (maxTime > 30 * 1000) {
        div = 1000;
        type = "sec";
    }

    XYSeriesCollection result = new XYSeriesCollection();

    for (int i = 0; i < chartsCollection.getSeriesCount(); i++) {

        XYSeries old = chartsCollection.getSeries(i);
        XYSeries series = new XYSeries(old.getKey(), old.getAutoSort(), old.getAllowDuplicateXValues());
        for (int j = 0; j < old.getItemCount(); j++) {
            Number x = old.getX(j).doubleValue() / div;
            Number y = old.getY(j);
            series.add(x, y);
        }

        result.addSeries(series);
    }

    if (markers != null) {
        for (IntervalMarker marker : markers) {
            marker.setStartValue(marker.getStartValue() / div);
            marker.setEndValue(marker.getEndValue() / div);
        }
    }

    return Pair.of(type, result);
}

From source file:controller.DrawCurve.java

private XYDataset createDataset() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries series1 = new XYSeries("Red", false);
    XYSeries series2 = new XYSeries("Green", false);
    XYSeries series3 = new XYSeries("Blue", false);

    for (int Z = 0; Z < 256; Z++) {
        for (int i = 0; i < 3; i++) {
            if (i == 0) {
                series1.add(G[i][Z], Z);
            } else if (i == 1) {
                series2.add(G[i][Z], Z);
            } else {
                series3.add(G[i][Z], Z);
            }/*ww w . j  a va  2 s . com*/
        }
    }

    dataset.addSeries(series1);
    dataset.addSeries(series2);
    dataset.addSeries(series3);

    return dataset;
}

From source file:org.gwaspi.reports.GenericReportGenerator.java

public static XYDataset getSampleHetzygDataset(SampleQAHetzygPlotZoom sampleQAHetzygPlotZoom,
        OperationKey operationKey) throws IOException {

    XYDataset resultXYDataset;// www  .j  a  v  a  2s.co  m

    QASamplesOperationDataSet qaSamplesOpDS = (QASamplesOperationDataSet) OperationManager
            .generateOperationDataSet(operationKey);

    OperationMetadata rdOPMetadata = getOperationService().getOperationMetadata(operationKey);

    Map<Integer, SampleKey> samples = qaSamplesOpDS.getSamplesKeysSource().getIndicesMap();
    List<Double> hetzyRatios = (List) qaSamplesOpDS.getHetzyRatios(-1, -1);
    List<Double> missingRatios = (List) qaSamplesOpDS.getMissingRatios(-1, -1);

    //<editor-fold defaultstate="expanded" desc="BUILD XYDataset">
    XYSeries dataSeries = new XYSeries("");

    int count = 0;
    Map<String, SampleKey> samplesLabeler = new LinkedHashMap<String, SampleKey>();
    for (SampleKey tmpSampleKey : samples.values()) {
        double tmpHetzyVal = hetzyRatios.get(count);
        double tmpMissratVal = missingRatios.get(count);
        if (Double.isNaN(tmpHetzyVal) || Double.isInfinite(tmpHetzyVal)) {
            tmpHetzyVal = 0;
        }
        if (Double.isNaN(tmpMissratVal) || Double.isInfinite(tmpMissratVal)) {
            tmpMissratVal = 0;
        }

        dataSeries.add(tmpHetzyVal, tmpMissratVal);
        samplesLabeler.put(count + "_" + tmpMissratVal + "_" + tmpHetzyVal, tmpSampleKey);
        count++;
    }
    sampleQAHetzygPlotZoom.setLabelerMap(samplesLabeler);

    dataSeries.setDescription(rdOPMetadata.getDescription());

    resultXYDataset = new XYSeriesCollection(dataSeries);
    //</editor-fold>

    return resultXYDataset;
}

From source file:org.yooreeka.util.gui.XyGui.java

public XyGui(String title, double[] x) {

    super(title);

    errMsg = new StringBuilder();
    setLoopInt(x.length);//from   w ww.j  a va2 s .  c  o m

    if (checkX(x)) {

        XYSeries xydata = new XYSeries(title);

        for (int i = 0; i < loopInt; i++) {
            xydata.add(x[i], C.ZERO_DOUBLE);
        }

        xycollection = new XYSeriesCollection(xydata);

        final JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y", xycollection,
                PlotOrientation.VERTICAL, true, true, false);

        final XYPlot plot = chart.getXYPlot();

        final NumberAxis domainAxis = new NumberAxis("x");
        plot.setDomainAxis(domainAxis);

        final NumberAxis rangeAxis = new NumberAxis("y");
        plot.setRangeAxis(rangeAxis);

        chart.setBackgroundPaint(Color.white);
        plot.setOutlinePaint(Color.black);

        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);

    } else {
        System.err.println(errMsg.toString());
    }
}

From source file:org.yooreeka.util.gui.XyGui.java

public XyGui(String title, double[] x, double[] y) {

    super(title);

    errMsg = new StringBuilder();
    setLoopInt(x.length);//w  ww . j a  v  a 2s . c om

    if (checkX(x) && checkY(x.length, y)) {

        XYSeries xydata = new XYSeries(title);

        for (int i = 0; i < loopInt; i++) {
            xydata.add(x[i], y[i]);
        }

        xycollection = new XYSeriesCollection(xydata);

        final JFreeChart chart = ChartFactory.createXYLineChart(title + " (XY Plot)", "X", "Y", xycollection,
                PlotOrientation.VERTICAL, true, true, false);

        final XYPlot plot = chart.getXYPlot();

        final NumberAxis domainAxis = new NumberAxis("x");
        plot.setDomainAxis(domainAxis);

        final NumberAxis rangeAxis = new NumberAxis("y");
        plot.setRangeAxis(rangeAxis);

        chart.setBackgroundPaint(Color.white);
        plot.setOutlinePaint(Color.black);

        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);

    } else {
        System.err.println(errMsg.toString());
    }
}