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

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

Introduction

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

Prototype

public XYSeries(Comparable key, boolean autoSort, boolean allowDuplicateXValues) 

Source Link

Document

Constructs a new xy-series that contains no data.

Usage

From source file:playground.dgrether.analysis.charts.DgAvgDeltaUtilsModeQuantilesChart.java

private XYSeriesCollection createDatasets(String runId1, String runId2) {
    List<DgAnalysisPopulation> quantiles = this.ana.getQuantiles(this.nQuantiles,
            new DgPersonDataIncomeComparator());
    XYSeries car2carSeries = new XYSeries("Mean " + '\u0394' + "Utility Car2Car", false, true);
    XYSeries pt2ptSeries = new XYSeries("Mean " + '\u0394' + "Utility Pt2Pt", false, true);
    XYSeries pt2carSeries = new XYSeries("Mean " + '\u0394' + "Utility Pt2Car", false, true);
    XYSeries car2ptSeries = new XYSeries("Mean " + '\u0394' + "Utility Car2Pt", false, true);
    double quantile = -0.5;
    Double avgUtil = 0.0;/*from www. j av  a 2 s .c om*/
    double xLoc = 0.0;
    for (DgAnalysisPopulation p : quantiles) {
        quantile++;
        xLoc = quantile / this.nQuantiles;
        xLoc *= 100.0;
        DgModeSwitchPlanTypeAnalyzer modeSwitchAnalysis = new DgModeSwitchPlanTypeAnalyzer(p, runId1, runId2);
        DgAnalysisPopulation car2carPop = modeSwitchAnalysis
                .getPersonsForModeSwitch(new Tuple<String, String>(TransportMode.car, TransportMode.car));
        DgAnalysisPopulation pt2ptPop = modeSwitchAnalysis
                .getPersonsForModeSwitch(new Tuple<String, String>(TransportMode.pt, TransportMode.pt));
        DgAnalysisPopulation pt2carPop = modeSwitchAnalysis
                .getPersonsForModeSwitch(new Tuple<String, String>(TransportMode.pt, TransportMode.car));
        DgAnalysisPopulation car2ptPop = modeSwitchAnalysis
                .getPersonsForModeSwitch(new Tuple<String, String>(TransportMode.car, TransportMode.pt));
        if ((car2carPop != null) && (car2carPop.getPersonData().size() >= threshold)) {
            avgUtil = car2carPop.calcAverageScoreDifference(runId1, runId2);
            car2carSeries.add(xLoc, avgUtil);
        }
        if ((pt2ptPop != null) && (pt2ptPop.getPersonData().size() >= threshold)) {
            avgUtil = pt2ptPop.calcAverageScoreDifference(runId1, runId2);
            pt2ptSeries.add(xLoc, avgUtil);
        }
        if ((pt2carPop != null) && (pt2carPop.getPersonData().size() >= threshold)) {
            avgUtil = pt2carPop.calcAverageScoreDifference(runId1, runId2);
            pt2carSeries.add(xLoc, avgUtil);
        }
        if ((car2ptPop != null) && (car2ptPop.getPersonData().size() >= threshold)) {
            avgUtil = car2ptPop.calcAverageScoreDifference(runId1, runId2);
            car2ptSeries.add(xLoc, avgUtil);
        }
    }
    XYSeriesCollection ds = new XYSeriesCollection();
    ds.addSeries(car2carSeries);
    ds.addSeries(pt2ptSeries);
    ds.addSeries(pt2carSeries);
    ds.addSeries(car2ptSeries);
    return ds;
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.diagnostics.ApproximationSetPlot.java

@Override
protected void update() {
    XYSeriesCollection dataset = new XYSeriesCollection();

    for (ResultKey key : frame.getSelectedResults()) {
        NondominatedPopulation population = new EpsilonBoxDominanceArchive(EPSILON);

        for (Accumulator accumulator : controller.get(key)) {
            if (!accumulator.keySet().contains(metric)) {
                continue;
            }/*from ww w .  j  a  v a2  s.  c  om*/

            List<?> list = (List<?>) accumulator.get(metric, accumulator.size(metric) - 1);

            for (Object object : list) {
                population.add((Solution) object);
            }
        }

        if (!population.isEmpty()) {
            XYSeries series = new XYSeries(key, false, true);

            for (Solution solution : population) {
                if (solution.getNumberOfObjectives() == 1) {
                    series.add(solution.getObjective(0), solution.getObjective(0));
                } else if (solution.getNumberOfObjectives() > 1) {
                    series.add(solution.getObjective(0), solution.getObjective(1));
                }
            }

            dataset.addSeries(series);
        }
    }

    JFreeChart chart = ChartFactory.createScatterPlot(metric, localization.getString("text.objective", 1),
            localization.getString("text.objective", 2), dataset, PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);

    for (int i = 0; i < dataset.getSeriesCount(); i++) {
        Paint paint = frame.getPaintHelper().get(dataset.getSeriesKey(i));

        renderer.setSeriesStroke(i, new BasicStroke(3f, 1, 1));
        renderer.setSeriesPaint(i, paint);
        renderer.setSeriesFillPaint(i, paint);
    }

    plot.setRenderer(renderer);

    //add overlay
    if (controller.getShowLastTrace() && (controller.getLastAccumulator() != null)
            && controller.getLastAccumulator().keySet().contains(metric)) {
        XYSeriesCollection dataset2 = new XYSeriesCollection();
        NondominatedPopulation population = new EpsilonBoxDominanceArchive(EPSILON);

        if (controller.getLastAccumulator().keySet().contains(metric)) {
            List<?> list = (List<?>) controller.getLastAccumulator().get(metric,
                    controller.getLastAccumulator().size(metric) - 1);

            for (Object object : list) {
                population.add((Solution) object);
            }
        }

        if (!population.isEmpty()) {
            XYSeries series = new XYSeries(localization.getString("text.last"), false, true);

            for (Solution solution : population) {
                series.add(solution.getObjective(0), solution.getObjective(1));
            }

            dataset2.addSeries(series);
        }

        XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(false, true);
        renderer2.setSeriesPaint(0, Color.BLACK);

        plot.setDataset(1, dataset2);
        plot.setRenderer(1, renderer2);
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    }

    removeAll();
    add(new ChartPanel(chart), BorderLayout.CENTER);
    revalidate();
    repaint();
}

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

/**
 * Confirm that cloning works./*from www  .  j av a 2s  . com*/
 */
public void testCloning() {
    DefaultTableXYDataset d1 = new DefaultTableXYDataset();
    XYSeries s1 = new XYSeries("Series 1", true, false);
    s1.add(1.0, 1.1);
    s1.add(2.0, 2.2);
    d1.addSeries(s1);

    DefaultTableXYDataset d2 = null;
    try {
        d2 = (DefaultTableXYDataset) d1.clone();
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }
    assertTrue(d1 != d2);
    assertTrue(d1.getClass() == d2.getClass());
    assertTrue(d1.equals(d2));

    s1.add(3.0, 3.3);
    assertFalse(d1.equals(d2));
}

From source file:lisong_mechlab.view.graphs.PayloadGraphPanel.java

public void updateGraph() {
    DefaultTableXYDataset dataset = new DefaultTableXYDataset();

    for (Entry entry : chassis) {
        XYSeries series = new XYSeries(entry.name, false, false);
        if (entry.representant instanceof ChassisStandard) {
            ChassisStandard chassisStandard = (ChassisStandard) entry.representant;
            List<Modifier> stockModifiers = new ArrayList<>(chassisStandard.getQuirks());
            stockModifiers.addAll(efficiencies.getModifiers());
            for (int rating = chassisStandard.getEngineMin(); rating <= chassisStandard
                    .getEngineMax(); rating += 5) {
                if (rating < 100) {
                    continue; // TODO: Remove this when they remove the engine limit.
                }//  w ww .jav a 2s . c o m
                double speed = TopSpeed.calculate(rating, chassisStandard.getMovementProfileBase(),
                        chassisStandard.getMassMax(), stockModifiers);
                series.add(speed, payloadStatistics.calculate(chassisStandard, rating));
            }
        } else {
            // Omnimech
            ChassisOmniMech chassisOmniMech = (ChassisOmniMech) entry.representant;
            Engine engine = chassisOmniMech.getFixedEngine();

            List<Modifier> stockModifiers = new ArrayList<>(chassisOmniMech.getStockModifiers());
            stockModifiers.addAll(efficiencies.getModifiers());

            double minSpeed = TopSpeed.calculate(engine.getRating(), chassisOmniMech.getMovementProfileMin(),
                    chassisOmniMech.getMassMax(), efficiencies.getModifiers());
            double stockSpeed = TopSpeed.calculate(engine.getRating(), chassisOmniMech.getMovementProfileBase(),
                    chassisOmniMech.getMassMax(), stockModifiers);
            double maxSpeed = TopSpeed.calculate(engine.getRating(), chassisOmniMech.getMovementProfileMax(),
                    chassisOmniMech.getMassMax(), efficiencies.getModifiers());

            double payload = payloadStatistics.calculate(chassisOmniMech);
            if (minSpeed != stockSpeed) {
                series.add(minSpeed, payload);
            }
            series.add(stockSpeed, payload);
            if (maxSpeed != stockSpeed) {
                series.add(maxSpeed, payload);
            }
        }
        dataset.addSeries(series);
    }
    setChart(makeChart(dataset));
    XYPlot plot = (XYPlot) getChart().getPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true);
    renderer.setBaseShapesFilled(false);
    plot.setRenderer(renderer);
}

From source file:org.xwiki.chart.internal.plot.AbstractXYPlotGenerator.java

/**
 * Extracts data columns from the {@link ChartModel} provided and populates the {@link DefaultTableXYDataset}
 * accordingly.//from  w ww .j av a2s  . com
 * 
 * @param model the {@link ChartModel} instance.
 * @param dataset the {@link DefaultTableXYDataset} to be populated.
 */
private void extractColumns(DefaultTableXYDataset dataset, ChartModel model) {
    for (int column = 0; column < model.getColumnCount(); column++) {
        XYSeries series = new XYSeries(model.getColumnHeader(column), false, false);
        for (int row = 0; row < model.getRowCount(); row++) {
            series.add(row, model.getCellValue(row, column));
        }
        dataset.addSeries(series);
    }
}

From source file:com.ivli.roim.controls.ChartView.java

@Override
public void OverlayChanged(OverlayChangeEvent anEvt) {
    LOG.debug(anEvt);//  w ww .  j a v a  2s.c  om

    if (anEvt.getObject() instanceof ROI) {
        XYSeriesCollection col = ((XYSeriesCollection) iPlot.getDataset());
        final OverlayManager mgr = (OverlayManager) anEvt.getSource();

        switch (anEvt.getCode()) {
        case CREATED: {
            assert (0 > col.indexOf(anEvt.getObject().getName()));

            final XYSeries s = new XYSeries(anEvt.getObject().getName(), true, false);
            final ISeries c = ((ROI) anEvt.getObject()).getSeries(Measurement.DENSITY);

            IMultiframeImage img = mgr.getImage();

            assert (c.size() == img.getTimeSliceVector().getNumFrames());

            for (int n = 0; n < c.size(); ++n)
                s.add(img.getTimeSliceVector().getSlices().get(n) / 1000., c.get(n));

            ((XYSeriesCollection) iPlot.getDataset()).addSeries(s);
            iPlot.getRenderer().setSeriesPaint(col.indexOf(anEvt.getObject().getName()),
                    ((ROI) anEvt.getObject()).getColor());
        }
            break;

        case DELETED: {
            final int ndx = col.indexOf(anEvt.getObject().getName());
            col.removeSeries(ndx);
        }
            break;

        case MOVED: {//fall-through                                                                      
            final int ndx = col.indexOf(anEvt.getObject().getName());
            ISeries c = ((ROI) anEvt.getObject()).getSeries(Measurement.DENSITY);
            XYSeries s = col.getSeries(ndx);
            s.setNotify(false);
            s.clear();

            for (int n = 0; n < c.size(); ++n) {
                long dur = mgr.getImage().getTimeSliceVector().getSlices().get(n) / 1000;
                s.add(dur, c.get(n));
            }
            s.setNotify(true);
            //s.fireSeriesChanged();

        }
            break;

        case COLOR_CHANGED: {
            assert (anEvt.getExtra() instanceof java.awt.Color);
            final int ndx = col.indexOf(anEvt.getObject().getName());
            iPlot.getRenderer().setSeriesPaint(ndx, ((ROI) anEvt.getObject()).getColor());
        }
            break;

        case NAME_CHANGED: {
            assert (anEvt.getExtra() instanceof String);
            LOG.debug("ROI" + (String) anEvt.getExtra() + "name changed to " + anEvt.getObject().getName());

            final int ndx = col.indexOf(((String) anEvt.getExtra()));

            col.getSeries(ndx).setKey(anEvt.getObject().getName());
            /* this is a work-around the case when two or more ROI have the same names (user mistakenly renamed) 
             * when this mistake is corrected it might happen the colors of curves does not match colors of corresponding ROI 
             */
            iPlot.getRenderer().setSeriesPaint(ndx, ((ROI) anEvt.getObject()).getColor());

        }
            break;

        default:
            ///throw new java.lang.IllegalArgumentException();    
            break;
        }
    }
}

From source file:org.matsim.core.utils.charts.XYScatterChart.java

/**
 * Adds a new data series to the chart with the specified title.
 * <code>xs<code> and <code>ys</code> should have the same length. If not,
 * only as many items are shown as the shorter array contains.
 * // w  w w  .j  av  a  2s.c  o  m
 * @param title
 * @param xs
 *            The x values.
 * @param ys
 *            The y values.
 */
public void addSeries(final String title, final double[] xs, final double[] ys) {
    XYSeries series = new XYSeries(title, false, true);
    for (int i = 0, n = Math.min(xs.length, ys.length); i < n; i++) {
        series.add(xs[i], ys[i]);
    }
    this.dataset.addSeries(series);
}

From source file:org.matsim.core.utils.charts.XYLineChart.java

/**
 * Adds a new data series to the chart with the specified title.
 * <code>xs<code> and <code>ys</code> should have the same length. If not, only as many items
 * are shown as the shorter array contains.
 *
 * @param title/*  w  w  w  .  j a  v a 2s .  c o  m*/
 * @param xs The x values.
 * @param ys The y values.
 */
public final void addSeries(final String title, final double[] xs, final double[] ys) {
    XYSeries series = new XYSeries(title, false, true);
    for (int i = 0, n = Math.min(xs.length, ys.length); i < n; i++) {
        series.add(xs[i], ys[i]);
    }
    this.dataset.addSeries(series);
}

From source file:com.griddynamics.jagger.reporting.LatencyPlotReportProvider.java

public static XYSeriesCollection getSeriesCollection(int seriesCount) {
    XYSeriesCollection result = new XYSeriesCollection();
    Random rnd = new Random();
    for (int i = 0; i < seriesCount; i++) {
        XYSeries series = new XYSeries(i, false, false);
        result.addSeries(series);/*from  w  w w.java2 s. c o  m*/
        for (int t = 0; t < 100; t++) {
            series.add(t, rnd.nextInt(50));
        }
    }

    return result;
}

From source file:playground.yu.utils.charts.XYScatterLineChart.java

/**
 * Adds a new data series to the chart with the specified title.
 * <code>xs<code> and <code>ys</code> should have the same length. If not,
 * only as many items are shown as the shorter array contains.
 * //from ww  w.jav  a2 s .  com
 * @param title
 * @param xs
 *            The x values.
 * @param ys
 *            The y values.
 */
@Override
public void addSeries(final String title, final double[] xs, final double[] ys) {
    XYSeries series = new XYSeries(title, false, true);
    for (int i = 0, n = Math.min(xs.length, ys.length); i < n; i++) {
        series.add(xs[i], ys[i]);
    }
    this.dataset.addSeries(series);
}