Код: Выделить всё
Chart.js Zoom + Pan not working
body { font-family: sans-serif; padding: 20px; }
canvas { width: 800px; height: 400px; border: 1px solid #ccc; }
button { margin: 5px; }
Zoom ok, Pan not working
🔄 Reset Zoom
const ctx = document.getElementById('myChart').getContext('2d');
const chart = new Chart(ctx, {
type: 'line',
data: {
labels: Array.from({ length: 100 }, (_, i) => i),
datasets: [{
label: 'Values',
data: Array.from({ length: 100 }, () => Math.random() * 100),
borderColor: 'blue',
pointRadius: 0
}]
},
options: {
responsive: false,
plugins: {
zoom: {
pan: {
enabled: true,
mode: 'xy',
onPan: () => console.log('🖱 Pan triggered')
},
zoom: {
wheel: { enabled: true },
pinch: { enabled: true },
mode: 'xy',
onZoom: () => console.log('🔍 Zoom triggered')
}
}
}
}
});
Подробнее здесь: https://stackoverflow.com/questions/796 ... lugin-zoom