gpt4 book ai didi

highcharts - 在我的代码中替换 highcharts.each 因为它已被弃用

转载 作者:行者123 更新时间:2023-12-04 01:23:05 25 4
gpt4 key购买 nike

我有一些同步的 Highcharts ,并使用以下代码在鼠标移动时同步十字准线:

//catch mousemove event and have all charts' crosshairs move along indicated values on x axis
function syncronizeCrossHairs(chart) {
['mousemove', 'touchmove', 'touchstart'].forEach(function(eventType) {
var container = $(chart.container),
offset = container.offset(),
x;

container[0].addEventListener(eventType,
(function(evt) {
x = evt.clientX - chart.plotLeft - offset.left;
Highcharts.charts.forEach(ch => {
var e = ch.pointer.normalize(evt), // Find coordinates within the chart
points = [];
ch.series.forEach(s => {
var point = s.searchPoint(e, true);
if (point) {
point.setState();
if (s.visible) {
points.push(point)
}
}
})

if (points) {
var number = 0;
Highcharts.each(points, function(p, i) {
if (!p.series.visible) {
points.splice(i - number, 1);
number++;
}
})
if (points.length) {
ch.tooltip.refresh(points); // Show the tooltip
}
}
ch.xAxis[0].drawCrosshair(x, points[0])
})
}))
})
}

我现在收到以下控制台消息:

Highcharts 错误 #32:www.highcharts.com/errors/32/?Highcharts.each=Array.forEach

Highcharts.each: Array.forEach

有人可以建议我如何替换代码中的 Highcharts.each 命令吗?

谢谢

最佳答案

我认为改变:

Highcharts.each(points, function(p, i) {
if (!p.series.visible) {
points.splice(i - number, 1);
number++;
}
})

到:
points.forEach((p, i) => {
if (!p.series.visible) {
points.splice(i - number, 1);
number++;
}
})

应该够了。请在您的应用程序中测试它,如果它有帮助,请告诉我。

关于highcharts - 在我的代码中替换 highcharts.each 因为它已被弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62320347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com