该问题的解决方法是使用AmChart对象的“chartContainer”属性,而不是全局变量“chart”。使用“chartContainer”属性可以在图表对象内访问事件并获取相应的信息。
下面是一个示例代码,它演示了如何使用“chartContainer”属性来解决这个问题:
const chart = am5xy.create("chartdiv", am5xy.XYChart);
//在“chartContainer”对象中设置全局指针移动事件 chart.chartContainer.events.on("globalpointermove", function(ev) { console.log("X: " + ev.pointer.point.x + ", Y: " + ev.pointer.point.y); });
//在“seriesContainer”对象中设置特定系列的鼠标移动事件 chart.seriesContainer.events.on("globalpointermove", function(ev) { console.log("This is a series container move event"); });
使用这种方法,您可以轻松地在AmChart对象内访问全局指针移动事件。