Reputation: 740
I created a jfrechart as the first pic. After having zoomed it with mouse wheel, It showed as the second pic. How can I resize ChartPanel so that it can show all the zoomed chart?
I put the ChartPanel in a JScrollPane and updated its preferred size in its mouseWheelMoved event as follows. It did not work as I expected. It didn't show the whole chart and the font size of axises were also enlarged to unsuitable size.
public void mouseWheelMoved(MouseWheelEvent e) {
double factor = _chartPanel.getZoomInFactor();
Dimension dim = _chartPanel.getPreferredSize();
dim.width =(int)( dim.width*(1.0+factor)+1);
_chartPanel.setDomainZoomable(false);
_chartPanel.setPreferredSize(dim);;
_chartPanel.revalidate();
_chartPanel.setDomainZoomable(true);
}
Upvotes: 0
Views: 1151
Reputation: 205875
I'm not sure how to usefully mix zooming and scrolling. Absent a Minimal, Complete, Valid Example,
You can restore the original zoom state using restoreAutoBounds()
, as shown here.
Among the several ways to control chart size, mentioned here, overriding getPreferredSize()
seems like the best approach for the reasons mentioned here.
Also consider extending ChartPanel
to implement the Scrollable
interface, as discussed here.
Upvotes: 1