0

enter image description here

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);

        }
alex2410
  • 10,904
  • 3
  • 25
  • 41
frankli22586
  • 710
  • 6
  • 19
  • Please edit your question to include a [*Minimal, Complete, Valid Example*](http://stackoverflow.com/help/mcve) that shows your current approach. – trashgod Jan 19 '14 at 12:04

1 Answers1

1

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045