java - Jfree :how do CandleStick chart with hour period

标签 java android jfreechart

我想制作每小时周期的蜡烛图(android),并查找 afreeChart 库以供使用。基于 jfreeCharts 的 freechart。

我有一个带有每日周期的烛台示例:

公共(public)静态 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 不适用于非日期值。我在开发人员指南 Jfreechart 中查找 OHLC 类,但没有找到每小时方法。如何每小时创建一根蜡烛而不是每个日期期间创建一根蜡烛?也许有人有例子? 谢谢!

最佳答案

OHLCDataset 的实现中,OHLCSeriesCollection 包括addSeries(OHLCSeries series)OHLCSeries 允许添加add(RegularTimePeriod period, …),并且 RegularTimePeriod 包含子类 Hour。讨论了使用 Hour 的示例 here .

关于java - Jfree :how do CandleStick chart with hour period,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13353070/

相关文章:

java - 未知主机异常 : while connecting to database server

android - 来自 XML 字符串的 HashMap - Android

android - 从 Fragment 开始一个新的 Activity

java - 在 iReports 中调整 JFreeChart

java - ChartPanel 不适合 JPanel 的大小 (JFreeChart)

Java 将特殊字符 ¡ 和 ̧ 解码为 A?¡ 和 I?§

java - ConcurrentModifcationException 偶尔发生

java - 处理器核心数量与线程池大小的关系

android - 从 Android 调用 REST (POST) 网络服务

java - JfreeChart 修复饼图半径