Page 1 of 1

How to create Fatter Candlesticks?

Posted: Fri Sep 18, 2015 4:06 am
by aremington1612
I'm developing a Swing app that displays daily financial data, and have chosen to use JFreeChart. I was able to learn how to create a candlestick chart, but my problem lies in customization.

You see, what I'm aiming for is more along the lines of

Image

While, so far all I've been able to manage is

Image

No matter how far I zoom in, the candlesticks do not increase in width.

I'm fairly certain that somehow the thin candlesticks have something to do with being bound to a certain time range.. I've tried to remedy that but am not sure what I'm doing wrong here.

Code:

Code: Select all

    public void showStockHistory(OHLCDataset dataset, String stockName) {
    JFreeChart candleChart = ChartFactory.createCandlestickChart("History of " + stockName, "Date", "Stock Points", dataset, true);

    XYPlot plot = candleChart.getXYPlot();
        plot.setDomainPannable(true);
        plot.setRangePannable(true);

    ValueAxis domain = plot.getDomainAxis();
        domain.setAutoRange(true);

    NumberAxis range = (NumberAxis)plot.getRangeAxis();
        range.setUpperMargin(0.0D);
        range.setLowerMargin(0.0D);
        range.setAutoRange(true);
        range.setAutoRangeIncludesZero(false);

    ChartPanel chartPanel = new ChartPanel(candleChart);
        chartPanel.setMouseWheelEnabled(true);
        chartPanel.setMouseZoomable(true);

    getViewport().add(chartPanel);
    }

Re: How to create Fatter Candlesticks?

Posted: Mon Nov 16, 2015 9:59 am
by csongi
Hi,

I got suck on this one s well. I tried some tricks similar to aremington1612's attempts but no luck! Also tried playing around with the candlestickrenderer. Could you please hint on what the trick is to get candles adjustable in width as you zoom in!

thanks in advance!