As the title says: how can I add horizontal scrollbar to my candlestick chart I created with the JFreeChart? I want the user to be able to scroll horizontally through the chart when zoomed in. Right now the zooming in works but I can't move left or right. I tried putting ChartPanel into JScrollPane but that's a chartpanel, not the chart itself. My custom ChartPanel constructor:
public MyChartPanel(JFreeChart chart) {
super(chart);
lineDrawingControllers =new EventListenerList();
this.setMouseZoomable(false);
this.addMouseListener(mouseHandler);
this.addMouseMotionListener(mouseHandler);
this.setPopupMenu(null);
this.linePopupMenu=new JPopupMenu();
linePopupMenuListener=new LinePopupMenuListener();
}
My custom Jpanel where I create the Chart and ChartPanel and put the ChartPanel inside the JScrollPane:
public MyCandleStickChart() {
ohlcSeries = new OHLCSeries("Test data");
ohlcSeriesCollection = new OHLCSeriesCollection();
ohlcSeriesCollection.addSeries(ohlcSeries);
ohlcSeries=ohlcSeriesCollection.getSeries(0);
chart= ChartFactory.createCandlestickChart("Default Chart", "Time", "Value", ohlcSeriesCollection, true);
chart.getXYPlot().setOrientation(PlotOrientation.VERTICAL);
chartPanel=new MyChartPanel(chart);
chartPanel.setDisplayToolTips(false);
jScrollPane=new JScrollPane(chartPanel);
jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
add(jScrollPane);
add(tooltipPanel);
}
Then I add the MyCandleStickChart JPanel to the main application frame:
myCandleStickChart=new MyCandleStickChart();
applicationFrame.add(myCandleStickChart, BorderLayout.CENTER);