angular - Angular + ChartJS 添加resetZoom 按钮
问题描述
我添加了 chartjs 缩放插件,现在我想添加一个允许重置缩放的按钮。我看到的所有教程都使用了一个函数,仅在使用 chartjs 时效果很好。但是由于我的图表在一个 Angular 组件中并且在一个类中,我必须尝试 afaik 来访问一个方法。所以认为这将是与班级合作时的方式
myChart!: Chart;
...
this.myChart = new Chart('myChart', {
...
zoom:{
pan: {
enabled: true,
modifierKey:'alt',
mode: 'xy',
},
zoom :{
drag:{
enabled:true,
threshold: 1,
},
pinch: {
enabled: true
},
mode:'x',
}
}
},
onClick(e) {
console.log('onClick e'+e.native)
console.log(e.type);
}
...
resetChart()
{
this.myChart.resetZoom();
}
我的结果是,即使没有按下按钮,它也会触发 resetChart。意思是我不能再缩放也不能平移/捏/拖动所以我试着像这样通过 ViewChild 调用它
父组件.html
<button (click)="resetChart.resetChart()" id='resetZoomChart' value="reset">Reset Zoom</button>
父组件.ts
@ViewChild("resetChart", { static: false }) resetChart!: ViewChartComponent;
解决方案
推荐阅读
- python - LSTM 预测连续值
- cockroachdb - 无法从 Spring Data R2DBC 驱动程序连接到 CockroachCloud 免费(测试版)集群
- javascript - 如何设置输入文本?
- powershell - 使用两个等长数组执行数学运算
- javascript - 使用extendscript制作后效组合矩阵
- javascript - shadowElement.focus() — 不可能?
- python - tkinter 主循环和线程(在装饰器中)[已解决]
- python - 这是一个字典练习。我对如何做到这一点感到困惑。有人可以帮我解决这个问题吗?
- javascript - 在 React 状态下使用原型
- javascript - 在角度 9 的 mat-table 中将可编辑字段添加到 mat-row