Highcharts setData最大调用堆栈超出

7z5jn7bk  于 2023-10-20  发布在  Highcharts
关注(0)|答案(2)|浏览(115)

我正在使用highcharts,我想点击一个点,并有一个模型弹出,并能够改变一个按钮,并改变颜色和点的符号。我可以改变一个点,但是当我点击下一个点时。我得到Uncaught RangeError:超过最大调用堆栈大小。任何帮助将是伟大的!

var update;
// point click event function
function showModal(p) {  
    update = p;
    var d = moment(p.point.x).format('M/D/YYYY H:mm');
    $('#point-date').html(d);
    $('#point-value').html(p.point.y);
    $('#point-flag').val(p.point.flag);
    $('#pointModal').modal('show');
}

// Clicking save on modal
function saveFlag() {

    var newData = update.point.series.data;
    var dataPoint = newData.filter(function (r) {
        return r.SiteID == update.point.SiteID && r.Date_Time == update.point.Date_Time
    });
    if (dataPoint != null && dataPoint.length > 0) {
        var size = 2;
        if (data.length < 50)
            size = 4;

        var value = $('#point-flag').val();
        dataPoint[0].marker.radius = size;
        dataPoint[0].marker.symbol = getSymbol(value);
        dataPoint[0].colorIndex = getColorIndex(value);
        dataPoint[0].flag = value;

        for (var index in timeseries.series) {
            if (timeseries.series[index].name == update.point.series.name) {
                timeseries.series[index].setData(newData);
            }
        }
    }
    $('#pointModal').modal('hide');
}
p5fdfcr1

p5fdfcr11#

我的理解是,在这个例子中,timeseries.series引用了这个API,并且是一个数组。要遍历数组,我不想使用for...in,而是for...of,它返回每个元素:

for (var series of timeseries.series) {
            if (series.name == update.point.series.name) {
                series.setData(newData);
            }
        }

请参阅:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in

dhxwm5r4

dhxwm5r42#

我知道如何更新一个点,这对我来说很有效。

var newData = update.point.series.data;
for (var index in timeseries.series) {
    if (timeseries.series[index].name == update.point.series.name) {
        for (var pointIndex in timeseries.series[index].data) {
            if (timeseries.series[index].data[pointIndex].SiteID == update.point.SiteID
                && timeseries.series[index].data[pointIndex].Date_Time == update.point.Date_Time) {
                    var value = $('#point-flag').val();
                    timeseries.series[index].data[pointIndex].update({
                        marker: { radius: 4, symbol: getSymbol(value) },
                        colorIndex: getColorIndex(value)
                    });
            }
        }
    }
}

相关问题