Search in sources :

Example 1 with CandlestickRenderer

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);
}
Also used : OHLCDataset(org.jfree.data.xy.OHLCDataset) TimeSeries(org.ta4j.core.TimeSeries) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) CandlestickRenderer(org.jfree.chart.renderer.xy.CandlestickRenderer) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

JFreeChart (org.jfree.chart.JFreeChart)1 NumberAxis (org.jfree.chart.axis.NumberAxis)1 XYPlot (org.jfree.chart.plot.XYPlot)1 CandlestickRenderer (org.jfree.chart.renderer.xy.CandlestickRenderer)1 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)1 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)1 OHLCDataset (org.jfree.data.xy.OHLCDataset)1 TimeSeries (org.ta4j.core.TimeSeries)1