我想用小时制作蜡烛图(android),并查看afreeChart库以供使用。 Afreechart基于jfreeCharts。
我举了一个日常烛台的例子:
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不适用于Date值。我在开发者指南Jfreechart中查找OHLC类,但没有找到每小时的方法。如何在每个小时期间创建一支蜡烛而不是每个日期期间一支蜡烛?也许有人有榜样? 谢谢!
答案 0 :(得分:2)
在OHLCDataset
的实施中,OHLCSeriesCollection
包含addSeries(OHLCSeries series)
。 OHLCSeries
允许一个add(RegularTimePeriod period, …)
,RegularTimePeriod
包含子类Hour
。我们讨论了使用Hour
的示例here。