I’m using CanvasJS since few weeks and I have a question about zoom.
I saw we can zoom easily by drag & drop but I would like to create a button to zoom (by click).
Example: I have a button “x2” and when i click on it it zooms x2 on my graph (no drag & drop, just a click).
I searched a lot and i found nothing.
Thank you in advance !
(Sorry my english isn’t perfect !)
To zoom into certain region, you need to change viewportMinimum and viewportMaximum. If you like to set viewportMinimum and viewportMaximum to certain region after clicking the button, you can achieve as shown in this jsfiddle.
Also take a look at this jsfiddle, where viewportMinimum and viewportMaximum are changed based on dropdown options.
When you change the viewport range by either zooming, panning or reset rangeChanging and rangeChanged events are fired. rangeChanging event is fired just before the current viewports are updated and the rangeChanged is fired on updation of the current viewports i.e. after zooming, panning or reset. An event parameter is passed to the event handler that you assign to the rangeChanging/rangeChanged event.This parameter contains current viewportMinimum, viewportMaximum and other properties.