Skip to content

Syncing axis zooms across multiple charts

This demo shows how we can sync zoom of an X-axes across multiple charts.

The function that performs syncing:

function syncAxes(targetChart) {
let targetAxis = targetChart.xAxes.getIndex(0);
if (targetAxis._skipSync != true) {
let start = targetAxis.get("start");
let end = targetAxis.get("end");
am5.array.each(chartsToSync, function(chart) {
if (chart != targetChart) {
let axis = chart.xAxes.getIndex(0);
axis._skipSync = true;
axis.setAll({
start: start,
end: end
})
axis._skipSync = false;
}
});
}
}

Using events to monitor changes to start and end settings on each axis:

// Set up syncing
xAxis.on("start", function() {
syncAxes(chart);
});
xAxis.on("end", function() {
syncAxes(chart);
});
Open in CodePen