Example usage for org.jfree.chart.axis SegmentedTimeline getSegment

List of usage examples for org.jfree.chart.axis SegmentedTimeline getSegment

Introduction

In this page you can find the example usage for org.jfree.chart.axis SegmentedTimeline getSegment.

Prototype

public Segment getSegment(Date date) 

Source Link

Document

Returns a segment that contains a date.

Usage

From source file:org.trade.ui.chart.CandlestickChart.java

/**
 * Method setNonTradingPeriods./*from w w  w.j  a v a2  s  . c o  m*/
 * 
 * @param start
 *            Date
 * @param end
 *            Date
 * @param segments15min
 *            int
 * @return List<Date>
 */
private List<Date> getNonTradingPeriods(Date startDate, Date endDate, Date openDate, Date closeDate,
        SegmentedTimeline segmentedTimeline) {
    /*
     * Add all 15min periods that are not trading times.
     */

    List<Date> noneTradingSegments = new ArrayList<Date>();
    do {
        /*
         * 96 15min periods per day
         */
        for (int j = 0; j < 96; j++) {
            Date segmentStartDate = TradingCalendar
                    .addMinutes(TradingCalendar.getSpecificTime(openDate, startDate), j * 15);
            if (!TradingCalendar.isTradingDay(segmentStartDate)
                    || !TradingCalendar.isMarketHours(openDate, closeDate, segmentStartDate)) {
                Segment segment = segmentedTimeline.getSegment(segmentStartDate);
                if (segment.inIncludeSegments()) {
                    noneTradingSegments.add(segmentStartDate);
                }
            }
        }
        startDate = TradingCalendar.addDays(startDate, 1);
    } while (endDate.after(startDate));

    return noneTradingSegments;
}

From source file:gui.DemoDatasetFactory.java

/**
 * Creates a sample high low dataset for a SegmentedTimeline
 *
 * @param timeline SegmenteTimeline that will use this dataset.
 * @param start Date from where the dataset will be generated. Actual dates will
 *        be generated dynamically based on the timeline.
 *
 * @return a sample high low dataset.//from   ww  w.  j av  a  2  s.c  o  m
 */
public static DefaultHighLowDataset createSegmentedHighLowDataset(SegmentedTimeline timeline, Date start) {

    // some open-high-low-close data
    double[][] data = { { 248.1999, 249.3999, 247.0499, 247.6999 }, { 247.4999, 250.6499, 246.7999, 249.3999 },
            { 249.5999, 249.7499, 247.4999, 248.5999 }, { 248.5999, 251.5499, 248.4999, 248.6499 },
            { 248.8499, 249.4499, 247.8499, 248.7999 }, { 249.1999, 250.5499, 248.4999, 248.7999 },
            { 249.2999, 251.1499, 248.9499, 249.1499 }, { 248.1499, 249.8999, 247.2999, 249.0499 },
            { 248.5999, 248.8999, 246.2999, 246.9499 }, { 247.1999, 248.3999, 246.6499, 248.3499 },
            { 246.0999, 246.5999, 244.4999, 244.5999 }, { 243.1999, 243.3999, 240.9499, 242.3499 },
            { 243.5999, 243.5999, 242.2499, 242.8999 }, { 242.4999, 243.1499, 241.5999, 242.8499 },
            { 244.1999, 247.0499, 243.7499, 246.9999 }, { 246.9499, 247.6499, 245.2999, 246.0499 },
            { 245.5999, 248.0999, 245.1999, 247.8999 }, { 247.9499, 247.9499, 243.8499, 243.9499 },
            { 242.1999, 245.9499, 242.1999, 244.7499 }, { 244.6499, 246.5999, 244.4999, 245.5999 },
            { 245.4499, 249.1999, 245.0999, 249.0999 }, { 249.0999, 250.2999, 248.4499, 249.2499 },
            { 249.4999, 249.8499, 246.7499, 246.8499 }, { 246.8499, 247.6499, 245.8999, 246.8499 },
            { 247.6999, 250.7999, 247.6999, 250.6999 }, { 250.8999, 251.4499, 249.0999, 249.4999 },
            { 249.6499, 252.4999, 249.5999, 251.6499 }, { 251.9499, 252.2999, 249.4999, 250.0499 },
            { 251.2499, 251.6999, 248.7999, 248.9499 }, { 249.0999, 250.2499, 247.9499, 249.7499 },
            { 250.0499, 251.1499, 249.4499, 249.9499 }, { 250.0499, 251.1499, 249.4499, 249.9499 },
            { 249.9999, 250.3499, 246.5999, 246.9499 }, { 247.0999, 249.6999, 246.8999, 249.2999 },
            { 249.8999, 252.9499, 249.8499, 252.3999 }, { 252.7999, 253.3499, 251.1999, 251.6999 },
            { 250.4999, 251.2999, 248.9499, 249.8999 }, { 250.6999, 253.4499, 250.6999, 253.1999 },
            { 252.9999, 253.8999, 252.2999, 253.2499 }, { 253.6999, 255.1999, 253.4999, 253.9499 },
            { 253.4499, 254.7999, 252.7999, 254.3499 }, { 253.4499, 254.5999, 252.4999, 254.2999 },
            { 253.5999, 253.8999, 251.6999, 251.7999 }, { 252.3499, 253.6999, 251.7999, 253.5499 },
            { 253.5499, 254.2499, 251.1999, 251.3499 }, { 251.2499, 251.9499, 249.9999, 251.5999 },
            { 251.9499, 252.5999, 250.2499, 251.9999 }, { 251.2499, 252.7499, 251.0999, 252.1999 },
            { 251.6499, 252.5499, 248.8499, 248.9499 }, { 249.6499, 249.8999, 248.5499, 249.0999 },
            { 249.3499, 250.4499, 248.9499, 250.0999 }, { 249.5499, 252.1499, 249.2999, 252.0499 },
            { 252.1499, 252.1499, 250.2499, 250.8499 }, { 251.2499, 254.9499, 250.9999, 254.4499 },
            { 254.0999, 255.1999, 253.4499, 254.5999 }, { 254.4999, 254.9499, 252.3999, 252.8999 },
            { 253.2999, 253.6499, 252.1499, 252.8999 }, { 253.4999, 254.1499, 251.8999, 252.0499 },
            { 252.3499, 254.4499, 252.3499, 254.2999 }, { 254.6499, 255.7499, 251.4499, 251.6499 },
            { 254.6499, 255.7499, 251.4499, 251.6499 }, { 252.2499, 253.1499, 251.5999, 252.9499 },
            { 253.4499, 253.9499, 251.0999, 251.4999 }, { 251.7499, 251.8499, 249.4499, 251.0999 },
            { 250.8499, 251.7999, 249.9499, 251.5499 }, { 251.5499, 252.1499, 250.3499, 251.5999 },
            { 252.9999, 254.9499, 252.7999, 254.8499 }, { 254.6999, 255.4499, 253.8999, 255.3499 },
            { 254.9999, 256.9500, 254.9999, 256.0999 }, { 256.4500, 258.2499, 255.3499, 258.1499 },
            { 257.4500, 258.6499, 257.2499, 257.9500 }, { 257.7499, 259.1499, 257.2000, 258.7999 },
            { 257.8999, 258.2000, 256.7499, 257.7000 }, { 257.9500, 260.2999, 257.5999, 259.9500 },
            { 259.2499, 260.4500, 258.8499, 259.4999 }, { 259.4500, 260.2499, 259.1499, 259.5499 },
            { 260.0499, 260.3499, 257.4999, 257.8999 }, { 257.8999, 261.9999, 257.3999, 261.8999 },
            { 261.8999, 262.5499, 259.8499, 261.6499 }, { 261.5499, 263.3499, 261.0999, 263.0499 },
            { 263.1499, 264.4500, 262.3499, 263.9999 }, { 264.1499, 264.2999, 261.8499, 262.7999 },
            { 262.6499, 263.2499, 261.5499, 262.9500 }, { 263.2999, 264.9500, 262.6499, 263.9500 },
            { 263.5999, 264.8499, 263.4500, 264.5999 }, { 264.7499, 268.0999, 264.7499, 267.2499 },
            { 266.3499, 267.7499, 265.7000, 266.8499 }, { 267.0999, 267.6499, 266.6499, 266.8499 },
            { 266.6499, 267.0499, 264.7499, 265.7499 }, { 265.4500, 265.7499, 264.2499, 264.8999 },
            { 265.3499, 266.4500, 265.2999, 265.5999 }, { 263.8499, 264.0499, 262.8499, 263.9999 },
            { 263.9500, 264.5499, 262.9500, 264.2999 }, { 264.5999, 265.5499, 262.7499, 262.7999 },
            { 263.3999, 263.5499, 261.3999, 261.8999 }, { 262.2000, 262.2000, 260.8499, 261.7000 },
            { 260.2499, 263.8499, 260.0999, 263.7000 }, { 263.2999, 266.0999, 263.2999, 265.8999 },
            { 266.2000, 266.9999, 264.8499, 266.6499 } };

    int m = data.length;

    Date[] date = new Date[m];
    double[] high = new double[m];
    double[] low = new double[m];
    double[] open = new double[m];
    double[] close = new double[m];
    double[] volume = new double[m];

    SegmentedTimeline.Segment segment = timeline.getSegment(start);
    for (int i = 0; i < m; i++) {
        while (!segment.inIncludeSegments()) {
            segment.inc();
        }
        date[i] = segment.getDate();
        open[i] = data[i][0];
        high[i] = data[i][1];
        low[i] = data[i][2];
        close[i] = data[i][3];

        segment.inc();
    }

    return new DefaultHighLowDataset("Series 1", date, high, low, open, close, volume);

}

From source file:com.jonas.testing.jfreechart.demos.DemoDatasetFactory.java

/**
 * Creates a sample high low dataset for a SegmentedTimeline
 *
 * @param timeline SegmenteTimeline that will use this dataset.
 * @param start Date from where the dataset will be generated. Actual dates will
 *        be generated dynamically based on the timeline.
 *
 * @return a sample high low dataset./*from ww w . j a va 2  s  .c  o  m*/
 */
public static DefaultHighLowDataset createSegmentedHighLowDataset(final SegmentedTimeline timeline,
        final Date start) {

    // some open-high-low-close data
    final double[][] data = { { 248.1999, 249.3999, 247.0499, 247.6999 },
            { 247.4999, 250.6499, 246.7999, 249.3999 }, { 249.5999, 249.7499, 247.4999, 248.5999 },
            { 248.5999, 251.5499, 248.4999, 248.6499 }, { 248.8499, 249.4499, 247.8499, 248.7999 },
            { 249.1999, 250.5499, 248.4999, 248.7999 }, { 249.2999, 251.1499, 248.9499, 249.1499 },
            { 248.1499, 249.8999, 247.2999, 249.0499 }, { 248.5999, 248.8999, 246.2999, 246.9499 },
            { 247.1999, 248.3999, 246.6499, 248.3499 }, { 246.0999, 246.5999, 244.4999, 244.5999 },
            { 243.1999, 243.3999, 240.9499, 242.3499 }, { 243.5999, 243.5999, 242.2499, 242.8999 },
            { 242.4999, 243.1499, 241.5999, 242.8499 }, { 244.1999, 247.0499, 243.7499, 246.9999 },
            { 246.9499, 247.6499, 245.2999, 246.0499 }, { 245.5999, 248.0999, 245.1999, 247.8999 },
            { 247.9499, 247.9499, 243.8499, 243.9499 }, { 242.1999, 245.9499, 242.1999, 244.7499 },
            { 244.6499, 246.5999, 244.4999, 245.5999 }, { 245.4499, 249.1999, 245.0999, 249.0999 },
            { 249.0999, 250.2999, 248.4499, 249.2499 }, { 249.4999, 249.8499, 246.7499, 246.8499 },
            { 246.8499, 247.6499, 245.8999, 246.8499 }, { 247.6999, 250.7999, 247.6999, 250.6999 },
            { 250.8999, 251.4499, 249.0999, 249.4999 }, { 249.6499, 252.4999, 249.5999, 251.6499 },
            { 251.9499, 252.2999, 249.4999, 250.0499 }, { 251.2499, 251.6999, 248.7999, 248.9499 },
            { 249.0999, 250.2499, 247.9499, 249.7499 }, { 250.0499, 251.1499, 249.4499, 249.9499 },
            { 250.0499, 251.1499, 249.4499, 249.9499 }, { 249.9999, 250.3499, 246.5999, 246.9499 },
            { 247.0999, 249.6999, 246.8999, 249.2999 }, { 249.8999, 252.9499, 249.8499, 252.3999 },
            { 252.7999, 253.3499, 251.1999, 251.6999 }, { 250.4999, 251.2999, 248.9499, 249.8999 },
            { 250.6999, 253.4499, 250.6999, 253.1999 }, { 252.9999, 253.8999, 252.2999, 253.2499 },
            { 253.6999, 255.1999, 253.4999, 253.9499 }, { 253.4499, 254.7999, 252.7999, 254.3499 },
            { 253.4499, 254.5999, 252.4999, 254.2999 }, { 253.5999, 253.8999, 251.6999, 251.7999 },
            { 252.3499, 253.6999, 251.7999, 253.5499 }, { 253.5499, 254.2499, 251.1999, 251.3499 },
            { 251.2499, 251.9499, 249.9999, 251.5999 }, { 251.9499, 252.5999, 250.2499, 251.9999 },
            { 251.2499, 252.7499, 251.0999, 252.1999 }, { 251.6499, 252.5499, 248.8499, 248.9499 },
            { 249.6499, 249.8999, 248.5499, 249.0999 }, { 249.3499, 250.4499, 248.9499, 250.0999 },
            { 249.5499, 252.1499, 249.2999, 252.0499 }, { 252.1499, 252.1499, 250.2499, 250.8499 },
            { 251.2499, 254.9499, 250.9999, 254.4499 }, { 254.0999, 255.1999, 253.4499, 254.5999 },
            { 254.4999, 254.9499, 252.3999, 252.8999 }, { 253.2999, 253.6499, 252.1499, 252.8999 },
            { 253.4999, 254.1499, 251.8999, 252.0499 }, { 252.3499, 254.4499, 252.3499, 254.2999 },
            { 254.6499, 255.7499, 251.4499, 251.6499 }, { 254.6499, 255.7499, 251.4499, 251.6499 },
            { 252.2499, 253.1499, 251.5999, 252.9499 }, { 253.4499, 253.9499, 251.0999, 251.4999 },
            { 251.7499, 251.8499, 249.4499, 251.0999 }, { 250.8499, 251.7999, 249.9499, 251.5499 },
            { 251.5499, 252.1499, 250.3499, 251.5999 }, { 252.9999, 254.9499, 252.7999, 254.8499 },
            { 254.6999, 255.4499, 253.8999, 255.3499 }, { 254.9999, 256.9500, 254.9999, 256.0999 },
            { 256.4500, 258.2499, 255.3499, 258.1499 }, { 257.4500, 258.6499, 257.2499, 257.9500 },
            { 257.7499, 259.1499, 257.2000, 258.7999 }, { 257.8999, 258.2000, 256.7499, 257.7000 },
            { 257.9500, 260.2999, 257.5999, 259.9500 }, { 259.2499, 260.4500, 258.8499, 259.4999 },
            { 259.4500, 260.2499, 259.1499, 259.5499 }, { 260.0499, 260.3499, 257.4999, 257.8999 },
            { 257.8999, 261.9999, 257.3999, 261.8999 }, { 261.8999, 262.5499, 259.8499, 261.6499 },
            { 261.5499, 263.3499, 261.0999, 263.0499 }, { 263.1499, 264.4500, 262.3499, 263.9999 },
            { 264.1499, 264.2999, 261.8499, 262.7999 }, { 262.6499, 263.2499, 261.5499, 262.9500 },
            { 263.2999, 264.9500, 262.6499, 263.9500 }, { 263.5999, 264.8499, 263.4500, 264.5999 },
            { 264.7499, 268.0999, 264.7499, 267.2499 }, { 266.3499, 267.7499, 265.7000, 266.8499 },
            { 267.0999, 267.6499, 266.6499, 266.8499 }, { 266.6499, 267.0499, 264.7499, 265.7499 },
            { 265.4500, 265.7499, 264.2499, 264.8999 }, { 265.3499, 266.4500, 265.2999, 265.5999 },
            { 263.8499, 264.0499, 262.8499, 263.9999 }, { 263.9500, 264.5499, 262.9500, 264.2999 },
            { 264.5999, 265.5499, 262.7499, 262.7999 }, { 263.3999, 263.5499, 261.3999, 261.8999 },
            { 262.2000, 262.2000, 260.8499, 261.7000 }, { 260.2499, 263.8499, 260.0999, 263.7000 },
            { 263.2999, 266.0999, 263.2999, 265.8999 }, { 266.2000, 266.9999, 264.8499, 266.6499 } };

    final int m = data.length;

    final Date[] date = new Date[m];
    final double[] high = new double[m];
    final double[] low = new double[m];
    final double[] open = new double[m];
    final double[] close = new double[m];
    final double[] volume = new double[m];

    final SegmentedTimeline.Segment segment = timeline.getSegment(start);
    for (int i = 0; i < m; i++) {
        while (!segment.inIncludeSegments()) {
            segment.inc();
        }
        date[i] = segment.getDate();
        open[i] = data[i][0];
        high[i] = data[i][1];
        low[i] = data[i][2];
        close[i] = data[i][3];

        segment.inc();
    }

    return new DefaultHighLowDataset("Series 1", date, high, low, open, close, volume);

}