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

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

Introduction

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

Prototype

public XYDataItem(double x, double y) 

Source Link

Document

Constructs a new data item.

Usage

From source file:org.nbheaven.sqe.codedefects.history.controlcenter.panels.SQEHistoryPanel.java

private void updateView() {
    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                updateView();//from   w  ww . j a  va2  s .  c  o m
            }
        });
        return;
    }

    assert SwingUtilities.isEventDispatchThread();

    // Update per project view first
    perProjectDataSet.removeAllSeries();
    XYSeries error = new XYSeries("Error", true, false);
    XYSeries warning = new XYSeries("Warning", true, false);
    XYSeries info = new XYSeries("Info", true, false);

    if (null != activeHistory) {
        int i = 1;
        for (History.Entry entry : activeHistory) {
            QualityResultStatistic result = entry.get(getSelectedProviders());
            error.add(new XYDataItem(i, result.getCodeDefectCount(CodeDefectSeverity.ERROR)));
            warning.add(new XYDataItem(i, result.getCodeDefectCount(CodeDefectSeverity.WARNING)));
            info.add(new XYDataItem(i, result.getCodeDefectCount(CodeDefectSeverity.INFO)));
            i++;
        }
        clearHistoryButton.setEnabled(!activeHistory.isEmpty());
    }

    perProjectDataSet.addSeries(error);
    perProjectDataSet.addSeries(warning);
    perProjectDataSet.addSeries(info);

    invalidate();
    revalidate();
    repaint();
}

From source file:com.mothsoft.alexis.web.ChartServlet.java

private boolean addSeries(final XYSeriesCollection seriesCollection, final String dataSetName,
        final List<DataSetPoint> points, final Timestamp startDate, final Integer numberOfSamples,
        final StandardXYItemRenderer renderer) {

    // create the series
    final XYSeries series = new XYSeries(dataSetName);
    Double total = 0.0d;/*from  w  w  w .  java2 s. c  om*/

    final Map<Date, Double> rawPoints = new LinkedHashMap<Date, Double>();

    final Calendar calendar = new GregorianCalendar();
    calendar.setTime(new Date(startDate.getTime()));

    for (int i = 0; i < numberOfSamples; i++) {
        rawPoints.put(calendar.getTime(), 0.0d);
        calendar.add(Calendar.HOUR_OF_DAY, 1);
    }

    for (final DataSetPoint ith : points) {
        final Date date = new Date(ith.getX().getTime());
        rawPoints.put(date, ith.getY());
        total += ith.getY();
    }

    for (final Map.Entry<Date, Double> entry : rawPoints.entrySet()) {
        final long x = entry.getKey().getTime();
        final Double y = entry.getValue();

        logger.debug("Adding point to series: (" + entry.getKey() + ", " + y + ")");

        series.add(new XYDataItem(x, (Number) y));
    }

    seriesCollection.addSeries(series);

    return total > 0;
}

From source file:org.jfree.data.xy.XYSeriesTest.java

/**
 * Some checks for the addOrUpdate() method.
 *//*from   w  ww  .j av  a 2  s. c o  m*/
@Test
public void testAddOrUpdate() {
    XYSeries series = new XYSeries("S1", true, false);
    XYDataItem old = series.addOrUpdate(new Long(1), new Long(2));
    assertTrue(old == null);
    assertEquals(1, series.getItemCount());
    assertEquals(new Long(2), series.getY(0));

    old = series.addOrUpdate(new Long(2), new Long(3));
    assertTrue(old == null);
    assertEquals(2, series.getItemCount());
    assertEquals(new Long(3), series.getY(1));

    old = series.addOrUpdate(new Long(1), new Long(99));
    assertEquals(new XYDataItem(new Long(1), new Long(2)), old);
    assertEquals(2, series.getItemCount());
    assertEquals(new Long(99), series.getY(0));
    assertEquals(new Long(3), series.getY(1));
}

From source file:org.jfree.data.xy.XYSeries.java

/**
 * Adds new data to the series and, if requested, sends a
 * {@link SeriesChangeEvent} to all registered listeners.
 * <P>/* w w  w. ja  v  a 2  s  .  c  o  m*/
 * Throws an exception if the x-value is a duplicate AND the
 * allowDuplicateXValues flag is false.
 *
 * @param x  the x-value (<code>null</code> not permitted).
 * @param y  the y-value (<code>null</code> permitted).
 * @param notify  a flag the controls whether or not a
 *                {@link SeriesChangeEvent} is sent to all registered
 *                listeners.
 */
public void add(Number x, Number y, boolean notify) {
    // delegate argument checking to XYDataItem...
    XYDataItem item = new XYDataItem(x, y);
    add(item, notify);
}

From source file:org.jfree.data.xy.XYSeries.java

/**
 * Adds new data to the series and, if requested, sends a
 * {@link SeriesChangeEvent} to all registered listeners.
 * <P>/*  w w  w . j  a v a  2 s  .  com*/
 * Throws an exception if the x-value is a duplicate AND the
 * allowDuplicateXValues flag is false.
 *
 * @param x  the x-value (<code>null</code> not permitted).
 * @param y  the y-value (<code>null</code> permitted).
 * @param notify  a flag the controls whether or not a
 *                {@link SeriesChangeEvent} is sent to all
 *                registered listeners.
 */
public void add(Number x, Number y, boolean notify) {

    // delegate argument checking to XYDataItem...
    XYDataItem item = new XYDataItem(x, y);

    add(item, notify);
}

From source file:MSUmpire.LCMSPeakStructure.LCMSPeakMS1.java

public void GenerateMassCalibrationRTMap() throws IOException {
    String pngfile = FilenameUtils.getFullPath(ScanCollectionName) + "/"
            + FilenameUtils.getBaseName(ScanCollectionName) + "_masscaliRT.png";
    XYSeries series = new XYSeries("PSM");
    XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
    LoessInterpolator loessInterpolator = new LoessInterpolator(0.75, //bandwidth,
            2//robustnessIters
    );//from   www.  j  a  va 2s .  c  om

    for (PSM psm : this.IDsummary.PSMList.values()) {
        float ppm = InstrumentParameter.CalcSignedPPM(psm.ObserPrecursorMass, psm.NeutralPepMass);
        series.add(new XYDataItem(psm.RetentionTime, ppm));
    }
    double x[] = new double[IDsummary.PSMList.size()];
    double y[] = new double[x.length];
    double currentmin = 0f;
    for (int i = 0; i < series.getItemCount(); i++) {
        x[i] = (double) series.getX(i);
        if (x[i] <= currentmin) {
            x[i] = currentmin + 0.0001f;
        }
        currentmin = x[i];
        y[i] = (double) series.getY(i);
    }

    Masscalibrationfunction = loessInterpolator.interpolate(x, y);
    XYSeries smoothline = new XYSeries("Loess Regression");

    double xvalue = x[0];

    while (xvalue < x[x.length - 1]) {
        smoothline.add(xvalue, Masscalibrationfunction.value(xvalue));
        xvalue += 0.05d;
    }
    xySeriesCollection.addSeries(smoothline);
    xySeriesCollection.addSeries(series);

    JFreeChart chart = ChartFactory.createScatterPlot("Mass calibration", "RT", "Mass error (ppm)",
            xySeriesCollection, PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyPlot = (XYPlot) chart.getPlot();
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);

    XYItemRenderer renderer = xyPlot.getRenderer();
    renderer.setSeriesPaint(1, Color.blue);
    renderer.setSeriesPaint(0, Color.BLACK);
    renderer.setSeriesShape(1, new Ellipse2D.Double(0, 0, 3, 3));
    renderer.setSeriesStroke(1, new BasicStroke(1.0f));
    xyPlot.setBackgroundPaint(Color.white);
    ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600);
}

From source file:com.planetmayo.debrief.satc_rcp.views.SpatialView.java

private void showBoundedStates(Collection<BoundedState> newStates) {
    if (newStates.isEmpty()) {
        return;//ww w  .  j a  v  a  2s .c o m
    }

    // just double-check that we're showing any states
    if (!_settings.isShowLegEndBounds() && !_settings.isShowAllBounds())
        return;

    String lastSeries = "UNSET";
    BoundedState lastState = null;
    int turnCounter = 1;
    int colourCounter = 0;

    @SuppressWarnings("rawtypes")
    HashMap<Comparable, Integer> keyToLegTypeMapping = new HashMap<Comparable, Integer>();

    // and plot the new data
    Iterator<BoundedState> iter = newStates.iterator();
    while (iter.hasNext()) {
        BoundedState thisS = iter.next();

        // get the poly
        LocationRange loc = thisS.getLocation();

        // ok, color code the series
        String thisSeries = thisS.getMemberOf();

        if (loc != null) {
            boolean showThisState = false;

            // ok, what about the name?
            String legName = "";

            if (thisSeries != lastSeries) {
                // are we storing leg ends?
                if (_settings.isShowLegEndBounds() || (lastSeries == null)) {
                    showThisState = true;

                    if (thisSeries != null)
                        legName = thisSeries;
                    else
                        legName = "Turn " + turnCounter++;
                }

                colourCounter++;

                // and remember the new series
                lastSeries = thisSeries;

            }

            // are we adding this leg?
            // if (!showThisState)
            // {
            // no, but are we showing mid=leg states?
            if (_settings.isShowAllBounds()) {
                // yes - we do want mid-way stats, better add it.
                showThisState = true;
                if (legName.length() > 0)
                    legName = "(" + legName + ") ";
                legName += _legendDateFormat.format(thisS.getTime());
            }
            // }

            // right then do we create a shape (series) for this one?
            if (showThisState) {
                // right, but do we show it for the new, or old state
                if (thisS.getMemberOf() == null) {
                    // right, we're already in a turn. use the last one
                    if (lastState != null)
                        loc = lastState.getLocation();
                } else {
                    // right this is the first point in a new leg. use this one
                    loc = thisS.getLocation();
                }

                // check we've found a shape
                if (loc != null) {
                    // ok, we've got a new series
                    XYSeries series = new XYSeries(legName, false);

                    Geometry geometry = loc.getGeometry();
                    Coordinate[] boundary = geometry.getCoordinates();
                    for (int i = 0; i < boundary.length; i++) {
                        Coordinate coordinate = boundary[i];
                        series.add(new XYDataItem(coordinate.y, coordinate.x));
                    }

                    keyToLegTypeMapping.put(series.getKey(), colourCounter);

                    _myData.addSeries(series);

                    int seriesIndex = _myData.getSeriesCount() - 1;

                    //                  final float dash1[] =
                    //                  { 10f, 10f };
                    //                  final BasicStroke dashed = new BasicStroke(1.0f ,
                    //                   BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1,
                    //                   0.0f);
                    final BasicStroke dashed = new BasicStroke(1f);

                    _renderer.setSeriesStroke(seriesIndex, dashed);

                    // _renderer.setSeriesStroke(seriesIndex, new BasicStroke());
                    _renderer.setSeriesLinesVisible(seriesIndex, true);
                    _renderer.setSeriesShapesVisible(seriesIndex, false);

                }
            }
        }

        // and move on
        lastState = thisS;
    }

    Color[] colorsList = getDifferentColors(colourCounter);

    // paint each series with color depending on leg type.
    for (Comparable<?> key : keyToLegTypeMapping.keySet()) {
        _renderer.setSeriesPaint(_myData.getSeriesIndex(key), colorsList[keyToLegTypeMapping.get(key) - 1]);

    }
}

From source file:jspritTest.util.Plotter.java

private void addJob(XYSeries activities, Job job) {
    if (job instanceof Shipment) {
        Shipment s = (Shipment) job;/* w w  w .  j  a  v a 2  s.  c  o  m*/
        Coordinate pickupCoordinate = getCoordinate(s.getPickupLocation().getCoordinate());
        XYDataItem dataItem = new XYDataItem(pickupCoordinate.getX() * scalingFactor,
                pickupCoordinate.getY() * scalingFactor);
        activities.add(dataItem);
        addLabel(s, dataItem);
        markItem(dataItem, Activity.PICKUP);
        containsPickupAct = true;

        Coordinate deliveryCoordinate = getCoordinate(s.getDeliveryLocation().getCoordinate());
        XYDataItem dataItem2 = new XYDataItem(deliveryCoordinate.getX() * scalingFactor,
                deliveryCoordinate.getY() * scalingFactor);
        activities.add(dataItem2);
        addLabel(s, dataItem2);
        markItem(dataItem2, Activity.DELIVERY);
        containsDeliveryAct = true;
    } else if (job instanceof Pickup) {
        Pickup service = (Pickup) job;
        Coordinate coord = getCoordinate(service.getLocation().getCoordinate());
        XYDataItem dataItem = new XYDataItem(coord.getX() * scalingFactor, coord.getY() * scalingFactor);
        activities.add(dataItem);
        addLabel(service, dataItem);
        markItem(dataItem, Activity.PICKUP);
        containsPickupAct = true;
    } else if (job instanceof Delivery) {
        Delivery service = (Delivery) job;
        Coordinate coord = getCoordinate(service.getLocation().getCoordinate());
        XYDataItem dataItem = new XYDataItem(coord.getX() * scalingFactor, coord.getY() * scalingFactor);
        activities.add(dataItem);
        addLabel(service, dataItem);
        markItem(dataItem, Activity.DELIVERY);
        containsDeliveryAct = true;
    } else if (job instanceof Service) {
        Service service = (Service) job; //down casting to specific Service class
        Coordinate coord = getCoordinate(service.getLocation().getCoordinate()); //get the service coordinate
        XYDataItem dataItem = new XYDataItem(coord.getX() * scalingFactor, coord.getY() * scalingFactor);
        activities.add(dataItem);
        if (this.label.equals(Label.SIZE))
            addLabel(service, dataItem); //let's see if we can extend this functionality to include additional labels
        else {
            String windowStart = String.valueOf(service.getTimeWindow().getStart());
            String windowEnd = String.valueOf(service.getTimeWindow().getEnd());
            String label = "{ID=" + job.getId() + ":" + windowStart + "-" + windowEnd + "}";
            labelsByDataItem.put(dataItem, label);
        }
        markItem(dataItem, Activity.SERVICE);
        containsServiceAct = true;
    } else {
        throw new IllegalStateException(
                "job instanceof " + job.getClass().toString() + ". this is not supported.");
    }
}

From source file:org.jfree.data.xy.XYSeries.java

/**
 * Adds or updates an item in the series and sends a
 * {@link SeriesChangeEvent} to all registered listeners.
 *
 * @param x  the x-value (<code>null</code> not permitted).
 * @param y  the y-value (<code>null</code> permitted).
 *
 * @return A copy of the overwritten data item, or <code>null</code> if no
 *         item was overwritten./*  w  w  w  . ja  va2s . c o m*/
 */
public XYDataItem addOrUpdate(Number x, Number y) {
    if (x == null) {
        throw new IllegalArgumentException("Null 'x' argument.");
    }

    // if we get to here, we know that duplicate X values are not permitted
    XYDataItem overwritten = null;
    int index = indexOf(x);
    if (index >= 0 && !this.allowDuplicateXValues) {
        XYDataItem existing = (XYDataItem) this.data.get(index);
        try {
            overwritten = (XYDataItem) existing.clone();
        } catch (CloneNotSupportedException e) {
            throw new SeriesException("Couldn't clone XYDataItem!");
        }
        existing.setY(y);
    } else {
        // if the series is sorted, the negative index is a result from
        // Collections.binarySearch() and tells us where to insert the
        // new item...otherwise it will be just -1 and we should just
        // append the value to the list...
        if (this.autoSort) {
            this.data.add(-index - 1, new XYDataItem(x, y));
        } else {
            this.data.add(new XYDataItem(x, y));
        }
        // check if this addition will exceed the maximum item count...
        if (getItemCount() > this.maximumItemCount) {
            this.data.remove(0);
        }
    }
    fireSeriesChanged();
    return overwritten;
}

From source file:com.graphhopper.jsprit.analysis.toolbox.Plotter.java

private void addJob(XYSeries activities, Job job) {
    if (job instanceof Shipment) {
        Shipment s = (Shipment) job;/*from  ww w  .  j  a  v  a  2  s.  c o m*/
        Coordinate pickupCoordinate = getCoordinate(s.getPickupLocation().getCoordinate());
        XYDataItem dataItem = new XYDataItem(pickupCoordinate.getX() * scalingFactor,
                pickupCoordinate.getY() * scalingFactor);
        activities.add(dataItem);
        addLabel(s, dataItem);
        markItem(dataItem, Activity.PICKUP);
        containsPickupAct = true;

        Coordinate deliveryCoordinate = getCoordinate(s.getDeliveryLocation().getCoordinate());
        XYDataItem dataItem2 = new XYDataItem(deliveryCoordinate.getX() * scalingFactor,
                deliveryCoordinate.getY() * scalingFactor);
        activities.add(dataItem2);
        addLabel(s, dataItem2);
        markItem(dataItem2, Activity.DELIVERY);
        containsDeliveryAct = true;
    } else if (job instanceof Pickup) {
        Pickup service = (Pickup) job;
        Coordinate coord = getCoordinate(service.getLocation().getCoordinate());
        XYDataItem dataItem = new XYDataItem(coord.getX() * scalingFactor, coord.getY() * scalingFactor);
        activities.add(dataItem);
        addLabel(service, dataItem);
        markItem(dataItem, Activity.PICKUP);
        containsPickupAct = true;
    } else if (job instanceof Delivery) {
        Delivery service = (Delivery) job;
        Coordinate coord = getCoordinate(service.getLocation().getCoordinate());
        XYDataItem dataItem = new XYDataItem(coord.getX() * scalingFactor, coord.getY() * scalingFactor);
        activities.add(dataItem);
        addLabel(service, dataItem);
        markItem(dataItem, Activity.DELIVERY);
        containsDeliveryAct = true;
    } else if (job instanceof Service) {
        Service service = (Service) job;
        Coordinate coord = getCoordinate(service.getLocation().getCoordinate());
        XYDataItem dataItem = new XYDataItem(coord.getX() * scalingFactor, coord.getY() * scalingFactor);
        activities.add(dataItem);
        addLabel(service, dataItem);
        markItem(dataItem, Activity.SERVICE);
        containsServiceAct = true;
    } else {
        throw new IllegalStateException(
                "job instanceof " + job.getClass().toString() + ". this is not supported.");
    }
}