作者:蓝颜知己Alice | 来源:互联网 | 2022-11-21 14:40
我有一个line-chart
,我想缩放它但无法做到。这是我的代码
let ctx = document.getElementById('myChart')
let chart = new Chart(ctx, {
type: 'line',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [7, 10, 3, 5, 2, 3],
fill: true,
backgroundColor: 'orange',
borderColor: 'green',
pointBorderColor: 'red',
pointBackgroundColor: 'red'
}]
},
options: {
plugins: {
pan: {
enabled: true,
mode: 'x',
onPan: function () { console.log('I was panned!!!'); }
},
zoom: {
enabled: true,
drag: true,
mode: 'x',
onZoom: function () { console.log('I was zoomed!!!'); }
},
},
responsive: true,
}
})
1> 小智..:
首先,您需要运行npm install --save chartjs-plugin-zoom与npm一起安装。
然后在您的ts文件中导入“ chartjs-plugin-zoom”。然后写这样的插件:
plugins: {
zoom: {
pan: {
enabled: true,
mode: 'x'
},
zoom: {
enabled: true,
mode: 'x'
}
}
},