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?

Thanks!

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)]
(https://demo.vaadin.com/javadoc/com.vaadin/vaadin-charts/4.0.0/com/vaadin/addon/charts/model/Axis.html#setExtremes-java.lang.Number-java.lang.Number-).

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.

Parameters:

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.]
(https://demo.vaadin.com/charts/#DynamicExtremes)

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.
Jens

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]
(https://demo.vaadin.com/charts/) so I recommend that you browse it a bit to see what can be done. Each example has the sources available.