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

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

Introduction

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

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if the series contains no data items, and false otherwise.

Usage

From source file:lu.lippmann.cdb.common.gui.ts.TimeSeriesChartUtil.java

private static void fillWithMultipleAxis(final Instances dataSet, final int dateIdx,
        final TimeSeriesCollection tsDataset, final JFreeChart tsChart) {
    final int numInstances = dataSet.numInstances();

    int axisNumber = 0;
    final Calendar cal = Calendar.getInstance();
    for (final Integer i : WekaDataStatsUtil.getNumericAttributesIndexes(dataSet)) {
        final TimeSeries ts = new TimeSeries(dataSet.attribute(i).name());
        for (int k = 0; k < numInstances; k++) {
            final long timeInMilliSec = (long) dataSet.instance(k).value(dateIdx);
            cal.setTimeInMillis(timeInMilliSec);
            if (dataSet.instance(k).isMissing(i)) {
                ts.addOrUpdate(new Millisecond(cal.getTime()), null);
            } else {
                ts.addOrUpdate(new Millisecond(cal.getTime()), dataSet.instance(k).value(i));
            }//from w  w w  . j a v  a2  s .  c  o m
        }
        if (!ts.isEmpty()) {
            if (axisNumber == 0) {
                tsDataset.addSeries(ts);
            } else {
                final XYPlot plot = tsChart.getXYPlot();
                final NumberAxis axisToAdd = new NumberAxis(dataSet.attribute(i).name());
                axisToAdd.setAutoRangeIncludesZero(false);
                plot.setRangeAxis(axisNumber, axisToAdd);
                final TimeSeriesCollection t = new TimeSeriesCollection();
                t.addSeries(ts);
                plot.setDataset(axisNumber, t);
                plot.mapDatasetToRangeAxis(axisNumber, axisNumber);
                final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
                renderer2.setSeriesPaint(0, ColorHelper.getColorForAString(dataSet.attribute(i).name()));
                plot.setRenderer(axisNumber, renderer2);
            }
            axisNumber++;
        }
    }
}

From source file:lu.lippmann.cdb.common.gui.ts.TimeSeriesChartUtil.java

private static void fillWithSingleAxis(final Instances dataSet, final int dateIdx,
        final TimeSeriesCollection tsDataset) {
    final int numInstances = dataSet.numInstances();

    final Calendar cal = Calendar.getInstance();
    for (final Integer i : WekaDataStatsUtil.getNumericAttributesIndexes(dataSet)) {
        if (dataSet.attributeStats(i).missingCount == dataSet.numInstances()) {
            System.out.println("TimeSeriesChartUtil: Only missing values for '" + dataSet.attribute(i).name()
                    + "', so skip it!");
            continue;
        }//from   w ww . j a va 2  s. c o m
        final TimeSeries ts = new TimeSeries(dataSet.attribute(i).name());
        for (int k = 0; k < numInstances; k++) {
            final Instance instancek = dataSet.instance(k);
            final long timeInMilliSec = (long) instancek.value(dateIdx);
            cal.setTimeInMillis(timeInMilliSec);

            if (instancek.isMissing(i)) {
                ts.addOrUpdate(new Millisecond(cal.getTime()), null);
            } else {
                ts.addOrUpdate(new Millisecond(cal.getTime()), instancek.value(i));
            }
        }
        if (!ts.isEmpty())
            tsDataset.addSeries(ts);
    }
}

From source file:action.ShowTimeSeriesWithForecastAction.java

/**
* Metoda obslugujaca zdarzenie, odpowiedzialna za inicjalizacje algorytmu genetycznego
*//*from w  ww.ja v a  2  s  . co m*/
public void actionPerformed(ActionEvent e) {

    try {

        if (window.getSliderSelekcji().getValue() + window.getSliderKrzyzowania().getValue()
                + window.getSliderMutacji().getValue() != 100)
            throw new ParseException(
                    "Please insert correct data for Selection, Crossing and Mutation. The sum of the three has to equal 100%",
                    0);

        TimeSeries timeSeries = window.getCurrentTimeSeries();
        if (timeSeries == null || timeSeries.isEmpty())
            throw new DataLengthException();

        SlidingTimeWindow slidingTimeWindow = new SlidingTimeWindow(
                this.parseToWindowForm(window.getTimeWindowField().getText()));

        if (window.getRdBtnStochastic().isSelected())
            GASettings.getInstance()
                    .setSelectionMethod(SelectionMethod.STOCHASTIC_UNIVERSAL_SAMPLING_SELECTION);

        if (window.getRdbtnArmaForecast().isSelected())
            GASettings.getInstance().setForecastMethod(ForecastMethod.ARMA_FORECAST);

        GASettings.getInstance().setConcurrent(true);

        ApplicationContext context = new AnnotationConfigApplicationContext(ForecastConfig.class);
        AbstractForecast forecast = (AbstractForecast) context.getBean("forecast");

        forecast.initializeGeneticAlgorithm((TimeSeries) timeSeries.clone(),
                (Integer) window.getPopulSizeField().getValue(), slidingTimeWindow,
                (Integer) window.getIterNumberField().getValue(),
                (double) window.getSliderProbOfCross().getValue() / 100,
                (double) window.getSliderProbOfMutat().getValue() / 100,
                (double) window.getSliderSelekcji().getValue() / 100,
                (double) window.getSliderKrzyzowania().getValue() / 100,
                (double) window.getSliderMutacji().getValue() / 100);
        forecast.initializeForecast((Integer) window.getPeriodOfPredField().getValue());

        forecast.addObserver(new GAChartObserver(window.getFitnessChart(),
                window.getTimeSeriesChartWithForecast(), (Integer) window.getPeriodOfPredField().getValue()));
        forecast.addObserver(new GAStatisticObserver(window.getForecast(),
                (Integer) window.getPeriodOfPredField().getValue()));
        forecast.execute();
        window.getTabbedPane().setSelectedIndex(3);

    } catch (CloneNotSupportedException e1) {
        e1.printStackTrace();
    } catch (DataLengthException de) {
        JOptionPane.showMessageDialog(window, "Current data is not set or empty", "Error",
                JOptionPane.ERROR_MESSAGE);
    } catch (ParseException pe) {
        JOptionPane.showMessageDialog(window, pe.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    } catch (Exception exc) {
        JOptionPane.showMessageDialog(window, "Wrong data", "Error", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:org.mwc.cmap.LiveDataMonitor.views.LiveDataMonitor.java

/**
 * a watchable item has been selected, better show it
 * /*from  ww w.j a  v a2s  . c  o m*/
 * @param attribute
 *          what we're going to watch
 */
private void storeDataset(final IAttribute attribute, final Object index) {
    final Vector<DataDoublet> data = attribute.getHistoricValues(index);

    // is there any data in it?
    if (data.size() == 0) {
        _chart.setTitle(attribute.getName());
        _chart.getXYPlot().setDataset(null);
    } else {
        final TimeSeriesCollection dataset = new TimeSeriesCollection();
        final TimeSeries series = new TimeSeries(attribute.getName());

        for (final Iterator<DataDoublet> iterator = data.iterator(); iterator.hasNext();) {
            final DataDoublet thisD = (DataDoublet) iterator.next();
            final Object thisVal = thisD.getValue();
            if (thisVal instanceof Number) {
                series.addOrUpdate(new Millisecond(new Date(thisD.getTime())), (Number) thisD.getValue());
            }
        }
        // did it work?
        if (!series.isEmpty()) {
            dataset.addSeries(series);
            _chart.getXYPlot().setDataset(dataset);
            _chart.setTitle(attribute.getName());
            _chart.getXYPlot().getRangeAxis().setLabel(attribute.getUnits());
        }
    }
}

From source file:org.esa.beam.timeseries.ui.graph.TimeSeriesGraphModel.java

@Override
public void addTimeSeries(List<TimeSeries> timeSeriesList, TimeSeriesType type) {
    final int timeSeriesCount;
    final int collectionOffset;
    if (TimeSeriesType.INSITU.equals(type)) {
        timeSeriesCount = displayAxisMapping.getInsituCount();
        collectionOffset = INSITU_COLLECTION_INDEX_OFFSET;
    } else {/*from  w  w w  . jav  a  2s  .  com*/
        timeSeriesCount = displayAxisMapping.getRasterCount();
        if (TimeSeriesType.CURSOR.equals(type)) {
            collectionOffset = CURSOR_COLLECTION_INDEX_OFFSET;
        } else {
            collectionOffset = PIN_COLLECTION_INDEX_OFFSET;
        }
    }
    final String[] aliasNames = getAliasNames();

    for (int aliasIdx = 0; aliasIdx < aliasNames.length; aliasIdx++) {
        final int targetCollectionIndex = collectionOffset + aliasIdx * 3;
        final TimeSeriesCollection targetTimeSeriesCollection = (TimeSeriesCollection) timeSeriesPlot
                .getDataset(targetCollectionIndex);
        if (targetTimeSeriesCollection != null) {
            targetTimeSeriesCollection.removeAllSeries();
        }
    }
    if (timeSeriesCount == 0) {
        return;
    }
    final int numPositions = timeSeriesList.size() / timeSeriesCount;
    int timeSeriesIndexOffset = 0;
    for (int posIdx = 0; posIdx < numPositions; posIdx++) {
        final Shape posShape = getShapeForPosition(type, posIdx);
        for (int aliasIdx = 0; aliasIdx < aliasNames.length; aliasIdx++) {
            final int targetCollectionIndex = collectionOffset + aliasIdx * 3;
            final TimeSeriesCollection targetTimeSeriesCollection = (TimeSeriesCollection) timeSeriesPlot
                    .getDataset(targetCollectionIndex);
            if (targetTimeSeriesCollection == null) {
                continue;
            }
            final XYItemRenderer renderer = timeSeriesPlot.getRenderer(targetCollectionIndex);
            final int dataSourceCount = getDataSourceCount(type, aliasNames[aliasIdx]);
            for (int ignoredIndex = 0; ignoredIndex < dataSourceCount; ignoredIndex++) {
                final TimeSeries currentTimeSeries = timeSeriesList.get(timeSeriesIndexOffset);
                targetTimeSeriesCollection.addSeries(currentTimeSeries);
                final int timeSeriesTargetIdx = targetTimeSeriesCollection.getSeriesCount() - 1;
                renderer.setSeriesShape(timeSeriesTargetIdx, posShape);
                renderer.setSeriesPaint(timeSeriesTargetIdx,
                        renderer.getSeriesPaint(timeSeriesTargetIdx % dataSourceCount));
                renderer.setSeriesVisibleInLegend(timeSeriesTargetIdx, !currentTimeSeries.isEmpty());
                timeSeriesIndexOffset++;
            }
            final ValueAxis axisForDataset = timeSeriesPlot.getDomainAxisForDataset(targetCollectionIndex);
            axisForDataset.configure();
        }
    }
    updateAnnotation(getCurrentView().getRaster());
}

From source file:de.citec.csra.allocation.vis.MovingChart.java

public void updateDataPoints(String id, String label, String resource, long start, long end, State state,
        Priority prio, boolean token) {
    synchronized (this.dataset) {
        TimeSeries series = this.dataset.getSeries(id);
        if (series == null) {
            series = new TimeSeries(id);
            this.dataset.addSeries(series);
        }/*from  w ww  .  j  a va 2  s  . co  m*/

        series.setDomainDescription(label);
        int stroke = -1;
        Color c = null;

        boolean randomcolor = false;
        if (!randomcolor) {
            switch (prio) {
            case EMERGENCY:
                c = Color.RED;
                break;
            case URGENT:
                c = Color.ORANGE;
                break;
            case HIGH:
                c = Color.YELLOW;
                break;
            case NORMAL:
                c = Color.GREEN;
                break;
            case LOW:
                c = Color.BLUE;
                break;
            case NO:
                c = Color.BLACK;
                break;
            }
        }

        switch (state) {
        case REQUESTED:
            stroke = 1;
            break;
        case SCHEDULED:
            stroke = 3;
            break;
        case ALLOCATED:
            stroke = 9;
            break;
        case RELEASED:
            stroke = 1;
            break;
        case REJECTED:
        case CANCELLED:
        case ABORTED:
            c = Color.GRAY;
            stroke = 1;
            break;
        }

        XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) this.chart.getXYPlot()
                .getRendererForDataset(dataset);

        int number = -1;
        for (int i = 0; i < this.dataset.getSeries().size(); i++) {
            TimeSeries t = this.dataset.getSeries(i);
            if (t.getKey().equals(id)) {
                number = i;
            }
        }
        if (number > 0) {
            if (stroke > 0) {
                if (token) {
                    r.setSeriesStroke(number,
                            new BasicStroke(stroke, CAP_BUTT, JOIN_BEVEL, 1, new float[] { 1.5f, .5f }, .5f));
                } else {
                    r.setSeriesStroke(number, new BasicStroke(stroke, CAP_BUTT, JOIN_BEVEL, 1));
                }
            }
            if (c != null) {
                r.setSeriesPaint(number, c);
            }
        }

        long channel;
        String key = resource; //prio
        if (values.containsKey(key)) {
            channel = values.get(key);
        } else {
            channel = events++;
            values.put(key, channel);
        }

        if (!series.isEmpty()) {
            series.clear();
        }
        series.addOrUpdate(new Millisecond(new Date(start)), channel);
        series.addOrUpdate(new Millisecond(new Date(end)), channel);
    }
}