Example usage for org.jfree.data.time TimeSeries add

List of usage examples for org.jfree.data.time TimeSeries add

Introduction

In this page you can find the example usage for org.jfree.data.time TimeSeries add.

Prototype

public void add(TimeSeriesDataItem item) 

Source Link

Document

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

Usage

From source file:org.pentaho.platform.uifoundation.chart.TimeSeriesCollectionChartDefinition.java

private void setDataByRow(final IPentahoResultSet data) {
    // TODO Make this routine MDX friendly
    if (data == null) {
        noDataMessage = Messages.getInstance().getString("CHART.USER_NO_DATA_AVAILABLE"); //$NON-NLS-1$
        return; // No data so we've got nothing to set
        // TODO come up with some sort of error strategy here.
    }//www. j  a  v  a2  s. c o  m
    Class timePeriodClass = TimeSeriesCollectionChartDefinition.getTimePeriodClass(getDomainPeriodType());
    Object[] rowData = data.next();
    while (rowData != null) {
        String seriesName = (String) rowData[0];
        TimeSeries wrkSeries = new TimeSeries(seriesName, timePeriodClass);
        for (int column = 1; column < rowData.length - 1; column = column + 2) {
            Date keyDate = getValidDate(rowData[column]);
            TimeSeriesDataItem timeSeriesDataItem = new TimeSeriesDataItem(RegularTimePeriod
                    .createInstance(timePeriodClass, keyDate, RegularTimePeriod.DEFAULT_TIME_ZONE),
                    ((Number) rowData[column + 1]).doubleValue());
            wrkSeries.add(timeSeriesDataItem);
        }
        addSeries(wrkSeries);
        rowData = data.next();
    }

    if ((data.getRowCount() > 0) && (this.getSeriesCount() <= 0)) {
        noDataMessage = Messages.getInstance().getString("CHART.USER_INCORRECT_DATA_FORMAT"); //$NON-NLS-1$
    }

}

From source file:org.mwc.debrief.track_shift.views.StackedDotHelper.java

/**
 * ok, our track has been dragged, calculate the new series of offsets
 * /*from w ww  .j  a  va2  s.c om*/
 * @param linePlot
 * @param dotPlot
 * @param onlyVis
 * @param showCourse
 * @param b
 * @param holder
 * @param logger
 * 
 * @param currentOffset
 *          how far the current track has been dragged
 */
public void updateBearingData(final XYPlot dotPlot, final XYPlot linePlot, final TrackDataProvider tracks,
        final boolean onlyVis, final boolean showCourse, final boolean flipAxes, final Composite holder,
        final ErrorLogger logger, final boolean updateDoublets) {
    // do we even have a primary track
    if (_primaryTrack == null)
        return;

    // ok, find the track wrappers
    if (_secondaryTrack == null)
        initialise(tracks, false, onlyVis, holder, logger, "Bearing", true, false);

    // did it work?
    // if (_secondaryTrack == null)
    // return;

    // ok - the tracks have moved. better update the doublets
    if (updateDoublets)
        updateDoublets(onlyVis, true, false);

    // aah - but what if we've ditched our doublets?
    if ((_primaryDoublets == null) || (_primaryDoublets.size() == 0)) {
        // better clear the plot
        dotPlot.setDataset(null);
        linePlot.setDataset(null);
        return;
    }

    // create the collection of series
    final TimeSeriesCollection errorSeries = new TimeSeriesCollection();
    final TimeSeriesCollection actualSeries = new TimeSeriesCollection();

    // produce a dataset for each track
    final TimeSeries errorValues = new TimeSeries(_primaryTrack.getName());

    final TimeSeries measuredValues = new TimeSeries("Measured");
    final TimeSeries ambigValues = new TimeSeries("Ambiguous Bearing");
    final TimeSeries calculatedValues = new TimeSeries("Calculated");

    final TimeSeries osCourseValues = new TimeSeries("Course");

    // ok, run through the points on the primary track
    final Iterator<Doublet> iter = _primaryDoublets.iterator();
    while (iter.hasNext()) {
        final Doublet thisD = iter.next();

        try {
            // obvious stuff first (stuff that doesn't need the tgt data)
            final Color thisColor = thisD.getColor();
            double measuredBearing = thisD.getMeasuredBearing();
            double ambigBearing = thisD.getAmbiguousMeasuredBearing();
            final HiResDate currentTime = thisD.getDTG();
            final FixedMillisecond thisMilli = new FixedMillisecond(currentTime.getDate().getTime());

            // put the measured bearing back in the positive domain
            if (measuredBearing < 0)
                measuredBearing += 360d;

            // stop, stop, stop - do we wish to plot bearings in the +/- 180 domain?
            if (flipAxes)
                if (measuredBearing > 180)
                    measuredBearing -= 360;

            final ColouredDataItem mBearing = new ColouredDataItem(thisMilli, measuredBearing, thisColor, false,
                    null);

            // and add them to the series
            measuredValues.add(mBearing);

            if (ambigBearing != Doublet.INVALID_BASE_FREQUENCY) {
                if (flipAxes)
                    if (ambigBearing > 180)
                        ambigBearing -= 360;

                final ColouredDataItem amBearing = new ColouredDataItem(thisMilli, ambigBearing, thisColor,
                        false, null);
                ambigValues.add(amBearing);
            }

            // do we have target data?
            if (thisD.getTarget() != null) {
                double calculatedBearing = thisD.getCalculatedBearing(null, null);
                final Color calcColor = thisD.getTarget().getColor();
                final double thisError = thisD.calculateBearingError(measuredBearing, calculatedBearing);
                final ColouredDataItem newError = new ColouredDataItem(thisMilli, thisError, thisColor, false,
                        null);

                if (flipAxes)
                    if (calculatedBearing > 180)
                        calculatedBearing -= 360;

                final ColouredDataItem cBearing = new ColouredDataItem(thisMilli, calculatedBearing, calcColor,
                        true, null);

                errorValues.add(newError);
                calculatedValues.add(cBearing);
            }

        } catch (final SeriesException e) {
            CorePlugin.logError(Status.INFO, "some kind of trip whilst updating bearing plot", e);
        }

    }

    // right, we do course in a special way, since it isn't dependent on the
    // target track. Do course here.
    HiResDate startDTG, endDTG;

    // just double-check we've still got our primary doublets
    if (_primaryDoublets == null) {
        CorePlugin.logError(Status.WARNING, "FOR SOME REASON PRIMARY DOUBLETS IS NULL - INVESTIGATE", null);
        return;
    }

    if (_primaryDoublets.size() == 0) {
        CorePlugin.logError(Status.WARNING, "FOR SOME REASON PRIMARY DOUBLETS IS ZERO LENGTH - INVESTIGATE",
                null);
        return;
    }

    startDTG = _primaryDoublets.first().getDTG();
    endDTG = _primaryDoublets.last().getDTG();

    if (startDTG.greaterThan(endDTG)) {
        System.err.println("in the wrong order, start:" + startDTG + " end:" + endDTG);
        return;
    }

    final Collection<Editable> hostFixes = _primaryTrack.getItemsBetween(startDTG, endDTG);

    // loop through th items
    for (final Iterator<Editable> iterator = hostFixes.iterator(); iterator.hasNext();) {
        final Editable editable = (Editable) iterator.next();
        final FixWrapper fw = (FixWrapper) editable;
        final FixedMillisecond thisMilli = new FixedMillisecond(fw.getDateTimeGroup().getDate().getTime());
        double ownshipCourse = MWC.Algorithms.Conversions.Rads2Degs(fw.getCourse());

        // stop, stop, stop - do we wish to plot bearings in the +/- 180 domain?
        if (flipAxes)
            if (ownshipCourse > 180)
                ownshipCourse -= 360;

        final ColouredDataItem crseBearing = new ColouredDataItem(thisMilli, ownshipCourse, fw.getColor(), true,
                null);
        osCourseValues.add(crseBearing);
    }

    // ok, add these new series

    if (showCourse) {
        actualSeries.addSeries(osCourseValues);
    }

    if (errorValues.getItemCount() > 0)
        errorSeries.addSeries(errorValues);

    actualSeries.addSeries(measuredValues);

    if (ambigValues.getItemCount() > 0)
        actualSeries.addSeries(ambigValues);

    if (calculatedValues.getItemCount() > 0)
        actualSeries.addSeries(calculatedValues);

    dotPlot.setDataset(errorSeries);
    linePlot.setDataset(actualSeries);
}

From source file:org.pentaho.platform.uifoundation.chart.TimeSeriesCollectionChartDefinition.java

private void setDataByColumn(final IPentahoResultSet data) {
    // TODO Make this routine MDX friendly
    if (data == null) {
        noDataMessage = Messages.getInstance().getString("CHART.USER_NO_DATA_AVAILABLE"); //$NON-NLS-1$
        return; // No data so we've got nothing to set
        // TODO come up with some sort of error strategy here.
    }/*  w ww  .ja v a2  s .  c  o  m*/
    boolean firstPass = true;
    String lastSeries = ""; //$NON-NLS-1$
    String seriesName = ""; //$NON-NLS-1$
    Class timePeriodClass = TimeSeriesCollectionChartDefinition.getTimePeriodClass(getDomainPeriodType());
    Object[] rowData = data.next();
    TimeSeries wrkSeries = null;
    while (rowData != null) {
        seriesName = (String) rowData[0];
        if (firstPass || !seriesName.equalsIgnoreCase(lastSeries)) {
            if (!firstPass) {
                addSeries(wrkSeries);
            }
            wrkSeries = new TimeSeries(seriesName, timePeriodClass);
            lastSeries = seriesName;
            firstPass = false;
        }
        Date keyDate = getValidDate(rowData[1]);
        RegularTimePeriod regularTimePeriod = RegularTimePeriod.createInstance(timePeriodClass, keyDate,
                RegularTimePeriod.DEFAULT_TIME_ZONE);
        TimeSeriesDataItem timeSeriesDataItem = new TimeSeriesDataItem(regularTimePeriod,
                ((Number) rowData[2]).doubleValue());
        if (wrkSeries != null) {
            wrkSeries.add(timeSeriesDataItem);
        }
        rowData = data.next();
    }
    if (!firstPass) {
        addSeries(wrkSeries);
    }
    if ((data.getRowCount() > 0) && (this.getSeriesCount() <= 0)) {
        noDataMessage = Messages.getInstance().getString("CHART.USER_INCORRECT_DATA_FORMAT"); //$NON-NLS-1$
    }

}

From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartHelper.java

/***********************************************************************************************
 * Preserve, Truncate or Decimate an XYDataset to try to achieve the requested display limit.
 * Decimation requested overrides all other modes.
 * Transform the dataset in accordance with the ChannelSelection Modes.
 * TRUNCATE is not currently used./*  w w w .  ja  v  a2 s.co  m*/
 *
 * ChartUpdate      isdecimated     Outcome
 *
 *  PRESERVE            N           Always PRESERVE, don't use displaylimit
 *                      Y           ditto
 *
 *  DECIMATE            N           Do same as PRESERVE
 *                      Y           Skip enough to leave displaylimit
 *
 *  TRUNCATE            N           Use only displaylimit, ignore isdecimated
 *                      Y           ditto
 *
 *
 * @param dataset
 * @param timezone
 * @param chartupdatetype
 * @param displaylimit
 * @param isdecimated
 * @param selectionmodes
 *
 * @return XYDataset
 */

private static XYDataset copyTransformedXYDataset(final XYDataset dataset, final TimeZone timezone,
        final DataUpdateType chartupdatetype, final int displaylimit, final boolean isdecimated,
        final List<ChannelSelectionMode> selectionmodes) {
    final String SOURCE = "ChartHelper.copyTransformedXYDataset() ";
    final DataUpdateType updateTypeToTransform;
    final XYDataset xyResult;

    // If decimation is NOT requested by the user for a DECIMATE chart then just do PRESERVE
    // Otherwise do exactly as the Chart configuration requests
    if ((DataUpdateType.DECIMATE.equals(chartupdatetype)) && (!isdecimated)) {
        updateTypeToTransform = DataUpdateType.PRESERVE;
    } else {
        updateTypeToTransform = chartupdatetype;
    }

    //        System.out.println(SOURCE + "displaylimit=" + displaylimit
    //                           + " isdecimated=" + isdecimated
    //                           + " chartupdatetype=" + chartupdatetype.getName()
    //                           + " updateTypeToTransform=" + updateTypeToTransform.getName());

    //-----------------------------------------------------------------------------------------
    // Use the whole dataset immediately if requested

    if (DataUpdateType.PRESERVE.equals(updateTypeToTransform)) {
        //System.out.println(SOURCE + "Preserve whole dataset");

        xyResult = dataset;

        return (xyResult);
    }

    //-----------------------------------------------------------------------------------------
    // Now do the transformation: TRUNCATE or DECIMATE

    if (dataset instanceof TimeSeriesCollection) {
        xyResult = new TimeSeriesCollection(timezone);

        // Process each Series in turn
        for (int intSeriesIndex = 0; intSeriesIndex < dataset.getSeriesCount(); intSeriesIndex++) {
            final TimeSeries timeSeriesInput;
            final TimeSeries timeSeriesOutput;

            timeSeriesInput = ((TimeSeriesCollection) dataset).getSeries(intSeriesIndex);

            // Make a TimeSeries based on Seconds...
            // whose name is the ChannelName
            timeSeriesOutput = new TimeSeries(timeSeriesInput.getKey(), timeSeriesInput.getTimePeriodClass());
            switch (updateTypeToTransform) {
            case TRUNCATE: {
                final int intStart;

                //System.out.println("truncate time series");
                if (timeSeriesInput.getItemCount() > displaylimit) {
                    intStart = timeSeriesInput.getItemCount() - displaylimit;
                } else {
                    intStart = 0;
                }

                // Modify each Series in exactly the same way!
                //                        timeSeriesOutput = timeSeriesInput.createCopy(intStart, timeSeriesInput.getItemCount()-1);

                for (int item = intStart; item < timeSeriesInput.getItemCount(); item++) {
                    timeSeriesOutput.add(timeSeriesInput.getDataItem(item));
                }

                break;
            }

            case DECIMATE: {
                final int intSkipCount;

                //System.out.println("decimate time series index=" + intSeriesIndex);
                if (timeSeriesInput.getItemCount() > displaylimit) {
                    intSkipCount = (timeSeriesInput.getItemCount() / displaylimit) - 1;
                } else {
                    // Show all of the data items, i.e. insufficient data to decimate
                    intSkipCount = 0;
                }

                for (int item = 0; item < timeSeriesInput.getItemCount(); item = item + intSkipCount + 1) {
                    timeSeriesOutput.add(timeSeriesInput.getDataItem(item));
                }

                break;
            }

            default: {
                LOGGER.error(SOURCE + MSG_UNSUPPORTED_UPDATE_TYPE);
            }
            }

            // Accumulate each Series in the output
            ((TimeSeriesCollection) xyResult).addSeries(timeSeriesOutput);
        }
    } else if (dataset instanceof XYSeriesCollection) {
        xyResult = new XYSeriesCollection();

        //System.out.println(SOURCE + "XYSeriesCollection for " + displaylimit + " samples");

        // Process each Series in turn
        for (int intSeriesIndex = 0; intSeriesIndex < dataset.getSeriesCount(); intSeriesIndex++) {
            final XYSeries xySeriesInput;
            final XYSeries xySeriesOutput;

            xySeriesInput = ((XYSeriesCollection) dataset).getSeries(intSeriesIndex);
            xySeriesOutput = new XYSeries(dataset.getSeriesKey(intSeriesIndex));

            switch (updateTypeToTransform) {
            case TRUNCATE: {
                final int intStart;

                //System.out.println("truncate xy");
                if (xySeriesInput.getItemCount() > displaylimit) {
                    intStart = xySeriesInput.getItemCount() - displaylimit;
                } else {
                    intStart = 0;
                }

                // Modify each Series in exactly the same way!
                //                        xySeriesOutput = xySeriesInput.createCopy(intStart, xySeriesInput.getItemCount()-1);

                for (int item = intStart; item < xySeriesInput.getItemCount(); item++) {
                    xySeriesOutput.add(xySeriesInput.getDataItem(item));
                }

                break;
            }

            case DECIMATE: {
                final int intSkipCount;

                //System.out.println("decimate xy series index=" + intSeriesIndex);
                if (xySeriesInput.getItemCount() > displaylimit) {
                    intSkipCount = (xySeriesInput.getItemCount() / displaylimit) - 1;
                } else {
                    // Show all of the data items, i.e. insufficient data to decimate
                    intSkipCount = 0;
                }

                for (int item = 0; item < xySeriesInput.getItemCount(); item = item + intSkipCount + 1) {
                    xySeriesOutput.add(xySeriesInput.getDataItem(item));
                }
                break;
            }

            default: {
                LOGGER.error(SOURCE + MSG_UNSUPPORTED_UPDATE_TYPE);
            }
            }

            // Accumulate each Series in the output
            ((XYSeriesCollection) xyResult).addSeries(xySeriesOutput);
        }
    } else {
        LOGGER.error(SOURCE + "Unsupported XYDataset type");

        xyResult = new XYSeriesCollection();
    }

    return (xyResult);
}