<分区>
如标题所述:如何将水平滚动条添加到我使用 JFreeChart 创建的烛台图表?我希望用户在放大时能够水平滚动图表。现在放大有效,但我不能向左或向右移动。我尝试将 ChartPanel 放入 JScrollPane 但那是一个图表面板,而不是图表本身。我的自定义 ChartPanel 构造函数:
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();
}
我的自定义 Jpanel,我在其中创建了 Chart 和 ChartPanel,并将 ChartPanel 放在 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);
}
然后我将 MyCandleStickChart JPanel 添加到主应用程序框架:
myCandleStickChart=new MyCandleStickChart();
applicationFrame.add(myCandleStickChart, BorderLayout.CENTER);