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

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

Introduction

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

Prototype

public TimeSeries(Comparable name) 

Source Link

Document

Creates a new (empty) time series.

Usage

From source file:org.jfree.data.time.TimeSeriesCollectionTest.java

@Test
public void testGetRangeBounds2() {
    TimeZone tzone = TimeZone.getTimeZone("Europe/London");
    Calendar calendar = new GregorianCalendar(tzone, Locale.UK);
    calendar.clear();// ww w .j av  a2s . c o m
    calendar.set(2014, Calendar.FEBRUARY, 23, 6, 0);
    long start = calendar.getTimeInMillis();
    calendar.clear();
    calendar.set(2014, Calendar.FEBRUARY, 24, 18, 0);
    long end = calendar.getTimeInMillis();
    Range range = new Range(start, end);

    TimeSeriesCollection collection = new TimeSeriesCollection(tzone);
    assertNull(collection.getRangeBounds(Collections.EMPTY_LIST, range, true));

    TimeSeries s1 = new TimeSeries("S1");
    s1.add(new Day(24, 2, 2014), 10.0);
    collection.addSeries(s1);
    assertEquals(new Range(10.0, 10.0), collection.getRangeBounds(Arrays.asList("S1"), range, true));
    collection.setXPosition(TimePeriodAnchor.MIDDLE);
    assertEquals(new Range(10.0, 10.0), collection.getRangeBounds(Arrays.asList("S1"), range, true));
    collection.setXPosition(TimePeriodAnchor.END);
    assertNull(collection.getRangeBounds(Arrays.asList("S1"), range, true));
}

From source file:tools.descartes.bungee.chart.ChartGenerator.java

public static XYPlot createDemandPlot(final List<ArrivalRateTuple> intensities,
        final IntensityDemandMapping mapping) {
    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    final TimeSeries series = new TimeSeries("resource demand");
    for (ArrivalRateTuple intensity : intensities) {
        long milliseconds = (referenceDate.getTime() / 1000 + (long) Math.floor(intensity.getTimeStamp()))
                * 1000;/*from w w  w . j ava 2 s .  co m*/
        series.add(new FixedMillisecond(milliseconds), mapping.getResourceDemand(intensity.getArrivalRate()));
    }
    dataset.addSeries(series);

    XYStepRenderer renderer = new XYStepRenderer();
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesStroke(0, new BasicStroke(STROKE_WIDTH));
    final NumberAxis rangeAxis = new NumberAxis("Resource Amount");
    rangeAxis.setAutoRangeIncludesZero(true);
    //rangeAxis.setRange(0,2.2);
    rangeAxis.setTickUnit(new NumberTickUnit(2));
    final XYPlot amountPlot = new XYPlot(dataset, null, rangeAxis, renderer);
    return amountPlot;
}

From source file:edu.jhuapl.graphs.jfreechart.JFreeChartTimeSeriesGraphSource.java

private TimeSeries buildTimeSeries(TimeSeriesInterface series, int i) throws GraphException {
    Map<String, Object> metadata = series.getMetadata();
    TimeResolution resolution;//from  w  w  w  .  j  a  v a 2 s. c o  m
    if (metadata.get(GraphSource.SERIES_TIME_RESOLUTION) instanceof TimeResolution) {
        resolution = (TimeResolution) metadata.get(GraphSource.SERIES_TIME_RESOLUTION);
    } else {
        resolution = DEFAULT_RESOLUTION;
    }

    String title = null;
    if (metadata.get(GraphSource.SERIES_TITLE) instanceof String) {
        title = (String) metadata.get(GraphSource.SERIES_TITLE);
    } else {
        title = "series" + i;
    }

    // This method will throw a graph exception if multiple points with the same resolved date are
    // present
    checkSeries(series, resolution);

    TimeSeries s = new TimeSeries(title);
    for (TimePointInterface point : series.getPoints()) {
        s.add(new MetadataTimeSeriesDataItem(makePeriod(point, resolution), point.getValue(),
                point.getMetadata()));
    }

    return s;
}

From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.SimpleXY_ChartPanel.java

private XYDataset createDeltaDataset(OSM_FabricDeltaCollection deltaHistory, Object userElement,
        String seriesName) {//from  ww w  .j a  va 2  s  .co m
    //      PortCounterName portCounter = null;
    //      MAD_Counter madCounter = null;
    //      OsmEvent osmEvent = null;
    //      
    //      if((Port != null) && (userElement instanceof PortCounterName))
    //        portCounter = (PortCounterName)userElement;
    //
    //      if((MAD_Stats != null) && (userElement instanceof MAD_Counter))
    //        madCounter = (MAD_Counter)userElement;
    //
    //      if((EventStats != null) && (userElement instanceof OsmEvent))
    //        osmEvent = (OsmEvent)userElement;
    //      
    TimeSeries series = new TimeSeries(seriesName);

    // iterate through the collection, and build up a time series
    for (int j = 0; j < deltaHistory.getSize(); j++) {
        OSM_FabricDelta delta = deltaHistory.getOSM_FabricDelta(j);

        // the dataset is a timeseries collection
        long lValue = 0;
        TimeStamp ts = null;
        RegularTimePeriod ms = null;

        if (Port != null) {
            // find the desired port counter, in this instance
            LinkedHashMap<String, PFM_PortChange> pcL = delta.getPortChanges();
            PFM_PortChange pC = pcL.get(OSM_Port.getOSM_PortKey(Port));
            lValue = pC.getDelta_port_counter(PortCounter);
            ts = pC.getCounterTimeStamp();

            // correct for missing time periods
            int deltaSeconds = delta.getDeltaSeconds();
            long sweepPeriod = delta.getFabric2().getPerfMgrSweepSecs();
            if (sweepPeriod < deltaSeconds) {
                // graph is reported as counts per period, so if the period is too long, interpolate
                lValue *= sweepPeriod;
                lValue /= deltaSeconds;
            }
        } else if (MADCounter != null) {
            // find the desired MAD counter, in this instance
            OSM_Stats mStats = delta.getStatChanges();
            lValue = MADCounter.getCounterValue(mStats);
            ts = delta.getTimeStamp();

            // correct for missing time periods
            int deltaSeconds = delta.getDeltaSeconds();
            long sweepPeriod = delta.getFabric2().getPerfMgrSweepSecs();
            if (sweepPeriod < deltaSeconds) {
                // graph is reported as counts per period, so if the period is too long, interpolate
                lValue *= sweepPeriod;
                lValue /= deltaSeconds;
            }
        } else if (EventType != null) {
            // find the desired Event counter, in this instance
            OSM_EventStats eStats = delta.getEventChanges();
            lValue = eStats.getCounter(EventType);
            ts = delta.getTimeStamp();

            // correct for missing time periods
            int deltaSeconds = delta.getDeltaSeconds();
            long sweepPeriod = delta.getFabric2().getPerfMgrSweepSecs();
            if (sweepPeriod < deltaSeconds) {
                // graph is reported as counts per period, so if the period is too long, interpolate
                lValue *= sweepPeriod;
                lValue /= deltaSeconds;
            }
        } else
            continue;

        ms = new FixedMillisecond(ts.getTimeInMillis());
        series.add(ms, (double) lValue);
    }
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);

    return dataset;
}

From source file:org.yccheok.jstock.gui.charting.InvestmentFlowChartJDialog.java

private XYDataset createInvestDataset() {
    final Currency localCurrency = org.yccheok.jstock.portfolio.Utils.getLocalCurrency();

    final TimeSeries series = new TimeSeries(GUIBundle.getString("InvestmentFlowChartJDialog_Invest"));

    this.totalInvestValue = 0.0;
    for (int i = 0, count = this.investSummary.size(); i < count; i++) {
        final Activities activities = this.investSummary.get(i);
        double amount = 0.0;
        for (int j = 0, count2 = activities.size(); j < count2; j++) {
            final Activity activity = activities.get(j);
            final Activity.Type type = activity.getType();
            final StockInfo stockInfo = (StockInfo) activity.get(Activity.Param.StockInfo);
            double exchangeRate = org.yccheok.jstock.portfolio.Utils.getExchangeRate(
                    this.portfolioManagementJPanel.getPortfolioRealTimeInfo(), localCurrency, stockInfo.code);

            if (type == Activity.Type.Buy) {
                amount += (activity.getAmount() * exchangeRate);
            } else if (type == Activity.Type.Sell) {
                amount -= (activity.getAmount() * exchangeRate);
            } else {
                assert (false);
            }/*from   www. j  a  v  a2s.  co m*/
        } // for (int j = 0, count2 = activities.size(); j < count2; j++)

        this.totalInvestValue += amount;

        final SimpleDate date = activities.getDate();
        final Date d = date.getTime();
        series.add(new Day(d), this.totalInvestValue);

    } // for (int i = 0, count = this.investSummary.size(); i < count; i++)

    return new TimeSeriesCollection(series);
}

From source file:WeatherFrame.java

private void OpenMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:     
    TimeSeries timeSeries = new TimeSeries("Data");
    weatherList ww = new weatherList();

    int returnVal = fc.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {

        File[] file = fc.getSelectedFiles();
        //This is where a real application would open the file.

        XmlReader filereader = new XmlReader();

        for (int i = 0; i < file.length; i++)
            filereader.ReadFile(file[i].getAbsoluteFile().toString(), ww);
        ww.sortList();//from   w ww  .  j  av a  2 s  .c o  m
        for (int i = 0; i < ww.getWeatherData().size(); i++) {
            //  System.out.println(ww.weatherData.get(i).getDateTime());
            timeSeries.addOrUpdate(new Day(ww.getWeatherData().get(i).getDateTime()),
                    ww.getWeatherData().get(i).getTemperature());
        }
        TempSet.addSeries(timeSeries);
    } else {
        System.out.println("Open command cancelled by user.\n");
    }
}

From source file:org.jfree.data.time.junit.TimeSeriesTest.java

/**
 * Some tests to ensure that the createCopy(int, int) method is
 * functioning correctly.//from  ww  w.jav  a2  s . c  om
 */
public void testCreateCopy2() {

    TimeSeries series = new TimeSeries("Series");
    series.add(new Month(MonthConstants.JANUARY, 2003), 45.0);
    series.add(new Month(MonthConstants.FEBRUARY, 2003), 55.0);
    series.add(new Month(MonthConstants.JUNE, 2003), 35.0);
    series.add(new Month(MonthConstants.NOVEMBER, 2003), 85.0);
    series.add(new Month(MonthConstants.DECEMBER, 2003), 75.0);

    try {
        // copy just the first item...
        TimeSeries result1 = series.createCopy(0, 0);
        assertEquals(new Month(1, 2003), result1.getTimePeriod(0));

        // copy the first two items...
        result1 = series.createCopy(0, 1);
        assertEquals(new Month(2, 2003), result1.getTimePeriod(1));

        // copy the middle three items...
        result1 = series.createCopy(1, 3);
        assertEquals(new Month(2, 2003), result1.getTimePeriod(0));
        assertEquals(new Month(11, 2003), result1.getTimePeriod(2));

        // copy the last two items...
        result1 = series.createCopy(3, 4);
        assertEquals(new Month(11, 2003), result1.getTimePeriod(0));
        assertEquals(new Month(12, 2003), result1.getTimePeriod(1));

        // copy the last item...
        result1 = series.createCopy(4, 4);
        assertEquals(new Month(12, 2003), result1.getTimePeriod(0));
    } catch (CloneNotSupportedException e) {
        assertTrue(false);
    }

    // check negative first argument
    boolean pass = false;
    try {
        /* TimeSeries result = */ series.createCopy(-1, 1);
    } catch (IllegalArgumentException e) {
        pass = true;
    } catch (CloneNotSupportedException e) {
        pass = false;
    }
    assertTrue(pass);

    // check second argument less than first argument
    pass = false;
    try {
        /* TimeSeries result = */ series.createCopy(1, 0);
    } catch (IllegalArgumentException e) {
        pass = true;
    } catch (CloneNotSupportedException e) {
        pass = false;
    }
    assertTrue(pass);

    TimeSeries series2 = new TimeSeries("Series 2");
    try {
        TimeSeries series3 = series2.createCopy(99, 999);
        assertEquals(0, series3.getItemCount());
    } catch (CloneNotSupportedException e) {
        assertTrue(false);
    }
}

From source file:org.jfree.data.time.TimeSeriesTest.java

/**
 * Checks that the min and max y values are updated correctly when copying
 * a subset.// w  w w .  j a v a  2s.  co  m
 *
 * @throws java.lang.CloneNotSupportedException
 */
@Test
public void testCreateCopy3() throws CloneNotSupportedException {
    TimeSeries s1 = new TimeSeries("S1");
    s1.add(new Year(2009), 100.0);
    s1.add(new Year(2010), 101.0);
    s1.add(new Year(2011), 102.0);
    assertEquals(100.0, s1.getMinY(), EPSILON);
    assertEquals(102.0, s1.getMaxY(), EPSILON);

    TimeSeries s2 = s1.createCopy(0, 1);
    assertEquals(100.0, s2.getMinY(), EPSILON);
    assertEquals(101.0, s2.getMaxY(), EPSILON);

    TimeSeries s3 = s1.createCopy(1, 2);
    assertEquals(101.0, s3.getMinY(), EPSILON);
    assertEquals(102.0, s3.getMaxY(), EPSILON);
}

From source file:view.App.java

private XYDataset createDataset(SpreadObject obj) throws ParseException {
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    TimeSeries series = new TimeSeries(
            obj.getBaseStock().getTicker() + " : " + obj.getSecondStock().getTicker());

    List<SpreadData> data = obj.getData();
    for (SpreadData item : data) {
        String date = item.getDate();
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date dateRes = df.parse(date);
        Day d = new Day(dateRes);
        RegularTimePeriod regTime = d.next();
        series.add(regTime, item.getSpreadValue().doubleValue());
    }/*from  w  ww. jav  a2 s.c  om*/

    dataset.addSeries(series);
    return dataset;
}

From source file:org.yccheok.jstock.gui.charting.InvestmentFlowChartJDialog.java

private synchronized JFreeChart createChart() {
    initSummaries(this.portfolioManagementJPanel);

    final XYDataset priceData = this.createInvestDataset();

    JFreeChart chart = ChartFactory.createTimeSeriesChart(" ",
            GUIBundle.getString("InvestmentFlowChartJDialog_Date"),
            GUIBundle.getString("InvestmentFlowChartJDialog_Value"), priceData, true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );/*from   ww w  . java2 s. c om*/

    XYPlot plot = chart.getXYPlot();

    NumberAxis rangeAxis1 = (NumberAxis) plot.getRangeAxis();
    final JStockOptions jStockOptions = JStock.instance().getJStockOptions();
    final String currencySymbol = jStockOptions.getCurrencySymbol(jStockOptions.getCountry());
    // Use apostrophes to escape currencySymbol. If currencySymbol contains
    // apostrophes, we may need to escape those by doubling them.
    //
    // 0 decimal place, to save up some display area.
    final NumberFormat currencyFormat = new DecimalFormat("'" + currencySymbol.replace("'", "''") + "'#,##0");
    rangeAxis1.setNumberFormatOverride(currencyFormat);

    plot.setRenderer(1, new StandardXYItemRenderer());
    this.ROITimeSeries = new TimeSeries(GUIBundle.getString("InvestmentFlowChartJDialog_ReturnOfInvestment"));
    plot.setDataset(1, new TimeSeriesCollection(this.ROITimeSeries));
    this.updateROITimeSeries();

    return chart;
}