简体   繁体   中英

Jfree:how do CandleStick chart with hour period

I want make candle chart(android) with hourly period, and looking the afreeChart library for use. Afreechart based on the jfreeCharts.

I have an example a candlestick with daily period:

public static OHLCDataset createDataset1() {

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

    int jan = 1;
    int feb = 2;

    for(int i = 0; i < 47; i++) {
        if(i <= 27) {
            date[i] = createDate(2001, jan, i+4, 12, 0);
        } else {
            date[i] = createDate(2001, feb, i-27, 12, 0);
        }
        high[i] = 45 + Math.random() * 20;
        low[i] = high[i] - (Math.random() * 30 + 3);
        do {
            open[i] = high[i] - Math.random() * (high[i] - low[i]);
            close[i] = low[i] + Math.random() * (high[i] - low[i]);
        } while(Math.abs(open[i] - close[i]) < 1);
    }

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

private static final Calendar calendar = Calendar.getInstance();

/**
 * Returns a date using the default locale and timezone.
 * @param y the year (YYYY).
 * @param m the month (1-12).
 * @param d the day of the month.
 * @param hour the hour of the day.
 * @param min the minute of the hour.
 * @return A date.
 */
private static Date createDate(int y, int m, int d, int hour, int min) {
    calendar.clear();
    calendar.set(y, m - 1, d, hour, min);
    return calendar.getTime();
}

DefaultHighLowDataset don't work with not Date values. I looking OHLC class in Developer Guide Jfreechart but don't find hourly methods. How create one candle every hour period instead of one candle every date period? Maybe someone have example? Thank you!

Among the implementations of OHLCDataset , OHLCSeriesCollection includes addSeries(OHLCSeries series) . An OHLCSeries allows one to add(RegularTimePeriod period, …) , and RegularTimePeriod includes the subclass Hour . An example using Hour is discussed here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM