angular - 在 Highcharts 上删除或切换事件
问题描述
如果为图表启用了“x”或“y”轴的缩放,我想设置不同的选择事件。问题是,我无法删除事件,只能向图表添加更多事件。
示例:Stackblitz Line:62-66 和 73、77
我想这样做的原因是,如果缩放类型从 x 更改为 y 并且我选择了一个区域(在图表中),则没有 x.min 或 x.max 值并且程序停止正确运行。
编辑: Stackblitz 新
我已经更新了示例以表示我想要做的事情。我使用程序在 xAxis 上打印出最小值和最大值的方法来初始化图表。如果我切换到 Y 轴缩放,我想打印 y 轴的最小值和最大值。问题是他没有删除图表的“选择事件”。
解决方案
好的,它适用于这些Stackblitz。我不知道为什么我在我的项目中遇到了麻烦或无法工作。我认为删除图表事件后更新缩放类型很重要:
Highcharts.removeEvent(this.chart, 'selection');
this.chart.update({ chart: { zoomType: 'y' } });
简短:使用Highcharts.removeEvent();
如果您遇到问题:property is not defined on "Static"
只需将以下代码添加到“@types/highcharts/index.d.ts”:
/**
* Removes an event that was added with Highcharts#addEvent
*
* @see {@link https://api.highcharts.com/class-reference/Highcharts#removeEvent}
*
* @param element The element to remove events on.
* @param type The type of events to remove. If undefined, all events are removed from the element.
* @param cb The specific callback to remove. If undefined, all events that match the element and optionally the type are removed.
*/
removeEvent(element: HTMLElement | ElementObject | object,
type?: string,
cb?: (evt: Event) => void): void;
推荐阅读
- spring - 如何使 DataJpaTest 刷新自动保存?
- reactjs - 反应复选框本地存储
- r - geom_smooth() 在 geom_point() 工作时不显示
- solr - 在 Drupal 7 上使用 Apache Solr 为搜索 API 配置 DDEV
- javascript - 我正在尝试保存并加载到本地存储,但我不断收到错误“未定义本地存储”
- c# - 在 C# 中删除 XML 序列化的 DefaultValue 属性
- excel - 如何仅使用 MIN-MAX 编写 excel 公式,而不使用 IF
- javascript - 如何将 React Native 中的状态保存到 Firebase
- python - Python / Discord:仅阻止某些人访问命令
- node.js - 为什么当我尝试在 expressjs 中下载文档时出现此错误“位置 0 的 JSON 中出现意外的令牌 %”