Currently possible using the options.plugins.zoom.pan.onPan/onZoom
callback functions. For an example, this will update a custom property with the chart's current bounds as the user pans and zooms. You can use this to load new data for the window (or load data for expected windows, as mentioned above).
// options.plugins.zoom.pan.onPan
(context) => {
const bounds = context.chart.getZoomedScaleBounds()
this.store.custom.write('bounds', bounds)
}
There's lots of room for customization here, see this page:
Not only can you specify the display format, but you can specify how date rounding occurs and you have control of display format for specific zoom levels using the options.scales[key].time.displayFormats
property.
This is a standard function, set options.plugins.zoom.zoom
to something like:
"zoom": {
"mode": "xy", // allow zooming for both the X and the Y axes
"drag": {
"enabled": true,
"modifierKey": "ctrl" // Control key must be held for dragging to start zooming
}
}
PS: The bounds property does not update in this example because I only added the script to the onPan
listener. It should have also been included in the onZoom
listener as well.
This example uses a double-click to reset the zoom, by assigning a double-click listener:
// events.beforeRender
(context) => {
context.canvas.ondblclick = () => {
context.resetZoom()
}
}
It's worth noting that this kind of interaction does not involve the Gateway. There's no client -> server -> client ping-pong happening: the client double clicks on the chart and the zoom is immediately reset.
I'm in the middle of a non-Perspective project at the moment, so it'll be a couple weeks before I can put together a sharable example of panning and zooming between real-time and historical data. However if you try it for yourself and run into issues I'd be more than happy to give input.