删除或切换高图表上的事件



如果为图表启用了"x"或"y"轴的缩放,则我想要设置不同的选择事件。问题是,我无法删除事件,只能向图表添加更多事件。

示例:堆栈闪电战线:62-66 和 73、77

我想这样做的原因是,如果缩放类型从 x 更改为 y,并且我选择一个区域(在图表中(,则没有 x.min 或 x.max 值,程序停止正常运行。

编辑:堆栈闪电战新

我已经更新了示例以表示我想做什么。我使用程序在 xAxis 上打印出最小值和最大值的方法初始化图表。如果我切换到 Y 轴缩放,我想打印 y 轴的最小值和最大值。问题是他没有删除图表的"选择事件"。

好的,它可以在这些堆栈闪电战中工作。我不知道为什么我遇到麻烦或在我的项目中不起作用。我认为在删除图表事件后更新缩放类型很重要:

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;

最新更新