Programmatically change zoom of chart without calling Chart::drawChart?

Hi there,

I have a chart that is updating dynamically. I would like to be able to position (/zoom) the chart such that the min and max are set to well-known numbers.

When I call XAxis::setMin and XAxis::setMax inside access() call, it does not have any effect unless I forcefully redraw the entire chart using Chart::drawChart. The scrollbar is enabled in the chart Configuration object.

Is there a way to cajoule the axis to the min/max I choose without forcing a redraw?


Hey. setMin and setMax is more meant for setting the range on the values axis, which most often is the YAxis. This is also more meant for setting up the chart before the initial paint, which is probably the reason that you need to call redraw(). For zoom, I suggest you try out [setExtremes(Number min, Number max)]

Sets the minimum and maximum of the axes after rendering has finished. If the startOnTick
and endOnTick options are true, the minimum and maximum values are rounded off to the
nearest tick. To prevent this, these options can be set to false before calling setExtremes.


min - The new minimum value

max - The new maximum value

This should do the trick that you want. [Here’s one example of it in use for dynamic extreme setting.]

Also note. chart.setTimeline(true); can be used to let the end user zoom and navigate freely. It adds a secondary “timeline” chart which the end user can control.

Hopefully this was what you were looking for.

Perfecto! Sorry I didn’t pick this up in the Javadoc on first glance. New to the API and there is a LOT to consume :slight_smile:

That’s fully understandable. The API is powerful but therefore also vast. :slight_smile: We’ve tried to highlight a lot of the features in the [demo]
( so I recommend that you browse it a bit to see what can be done. Each example has the sources available.