我使用OHLCSeries生成JFreeChart CandlestickChart。我扩展了CandlestickRenderer。在CandlestickRenderer中,我覆盖" public Paint getItemPaint(int series,int item)"在其中,我需要每个斯托克的日期信息做一些事情,但我不知道得到它,请帮我解决。
部分代码如下:
OHLCSeries ohlcSeries = new OHLCSeries("Price");
for(Records record : recordslist ) {
double h =...;
....
LocalDate actionday = record.getRecordsDay ();
int year = actionday.getYear();
int month = actionday.getMonthValue();
int day = actionday.getDayOfMonth();
ohlcSeries.add(new Day(day,month,year), open, high, low, close);
}
OHLCSeriesCollection candlestickDataset.addSeries(ohlcSeries);
JFreeChart candlestickChart = ChartFactory.createCandlestickChart("", "","", candlestickDataset, true);
DateAxis dayAxis = new DateAxis ();
candlestickChart.getXYPlot().setDomainAxis(dayAxis);
class AnalysisCandlestickRenderer extends CandlestickRenderer {
public Paint getItemPaint(int series, int item) {
//here I need every stoke's date info , how can I get it?
}
}
答案 0 :(得分:1)
根据此相关example中的建议,您可以使用传递给您的实施的OHLCSeriesCollection
和series
值访问数据集中的必填字段item
您的自定义getItemPaint()
中的CandlestickRenderer
。从完整的example开始,以下渲染器将生成显示的数据值。
代码:
private final OHLCSeriesCollection seriesCollection = new OHLCSeriesCollection();
…
class AnalysisCandlestickRenderer extends CandlestickRenderer {
@Override
public Paint getItemPaint(int series, int item) {
OHLCSeries currentSeries = seriesCollection.getSeries(series);
System.out.println(series + ": " + currentSeries.getPeriod(item));
return super.getItemPaint(item, item);
}
}
…
CandlestickRenderer r = new AnalysisCandlestickRenderer();
chart.getXYPlot().setRenderer(r);
控制台:
1: Wed Jan 01 12:00:00 EST 2014
1: Wed Jan 01 12:01:00 EST 2014
1: Wed Jan 01 12:02:00 EST 2014
1: Wed Jan 01 12:03:00 EST 2014
1: Wed Jan 01 12:04:00 EST 2014
0: Wed Jan 01 12:00:00 EST 2014
0: Wed Jan 01 12:01:00 EST 2014
0: Wed Jan 01 12:02:00 EST 2014
0: Wed Jan 01 12:03:00 EST 2014
0: Wed Jan 01 12:04:00 EST 2014
0: Wed Jan 01 12:05:00 EST 2014
0: Wed Jan 01 12:06:00 EST 2014
0: Wed Jan 01 12:07:00 EST 2014
0: Wed Jan 01 12:08:00 EST 2014
0: Wed Jan 01 12:09:00 EST 2014
图表: