4

When I enable the mouse wheel zoom in my chart using this code line:

chartPanel.setMouseWheelEnabled(true);

Scrolling the mouse wheel will zoom in/out both x and y axis. How can I disable mouse wheel zooming on one of the axis?

Jfreechart Version: 1.0.13

1 Answers1

3

Use the ChartPanel methods setDomainZoomable() and setRangeZoomable() to control the axes individually. As a concrete example, edit createChartPanel() in this example as follows to enable zoom on the "Value" axis, while leaving the "Count" axis unchanged:

panel.setMouseWheelEnabled(true);
panel.setDomainZoomable(true);
panel.setRangeZoomable(false);

For convenience,

  • Use the context menu to change the zoom settings as needed.

  • Use zoom buttons such as these as needed.

  • Use other applicable features described here.

Zoomed in: zoomed in

Zoomed out: zoomed out

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • setDomainZoomable() and setRangeZooomable() only affect left-mouse's drag zoom. Mouse wheel zoom still zoom both axis. Will update again later. – Achmad Fathoni Jul 04 '20 at 01:06
  • I am unable to reproduce the effect you describe with the complete example cited above. If you still have problems, please [edit] your question to include a [mcve] that exhibits the problem you describe. – trashgod Jul 04 '20 at 05:45
  • I just run your histogram with my java 11 on Kubuntu 20.04. The wheel still zoom both axis. I guess this problem is platfrom dependent. I can send a comment with screenshots as proof if you wish. – Achmad Fathoni Jul 04 '20 at 06:46
  • Ouch. No need for another [mcve]. Verify your JFreeChart version; I'm using JFreeChart version 1.5.0 on Java 1.8 on MacOS. – trashgod Jul 04 '20 at 07:08
  • 1
    The problem solved after I upgrade jfreechart to 1.5.0, thank you, accepting your answer. – Achmad Fathoni Jul 04 '20 at 07:44