use of org.jfree.chart.renderer.xy.CandlestickRenderer in project ta4j by ta4j.
the class CandlestickChart method main.
public static void main(String[] args) {
/*
Getting time series
*/
TimeSeries series = CsvTradesLoader.loadBitstampSeries();
/*
Creating the OHLC dataset
*/
OHLCDataset ohlcDataset = createOHLCDataset(series);
/*
Creating the additional dataset
*/
TimeSeriesCollection xyDataset = createAdditionalDataset(series);
/*
Creating the chart
*/
JFreeChart chart = ChartFactory.createCandlestickChart("Bitstamp BTC price", "Time", "USD", ohlcDataset, true);
// Candlestick rendering
CandlestickRenderer renderer = new CandlestickRenderer();
renderer.setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST);
XYPlot plot = chart.getXYPlot();
plot.setRenderer(renderer);
// Additional dataset
int index = 1;
plot.setDataset(index, xyDataset);
plot.mapDatasetToRangeAxis(index, 0);
XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
renderer2.setSeriesPaint(index, Color.blue);
plot.setRenderer(index, renderer2);
// Misc
plot.setRangeGridlinePaint(Color.lightGray);
plot.setBackgroundPaint(Color.white);
NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
numberAxis.setAutoRangeIncludesZero(false);
plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
/*
Displaying the chart
*/
displayChart(chart);
}
Aggregations