gpt4 book ai didi

javascript - Highcharts:与 setData 同步动态更新 dataLabels

转载 作者:行者123 更新时间:2023-12-03 00:27:59 26 4
gpt4 key购买 nike

我想与 setData 同步更新 dataLabels。

enter image description here

当我调用 setData 时,我想要更新 dataLabels,例如 1、2、3、... 100、... 1000。关于数字间隔的任何内容都可以。

var chart = Highcharts.chart('container', {
series: [{data: [1]}]
});
chart.series[0].setData([1000], true, {duration: 3000});

这是现场演示。 https://jsfiddle.net/Shinohara/hqsbcoum/11/

请问有人可以帮助我吗?

最佳答案

您可以在间隔函数中编辑dataLabel文本:

setTimeout(function() {
var newValue = 1000,
actualValue = chart.series[0].points[0].y,
dataLabelInterval,
counter = 1,
step = (newValue - actualValue) / 10;

chart.series[0].setData([newValue], true, {
duration: 3000
});

chart.series[0].points[0].dataLabel.attr({
text: actualValue
});

dataLabelInterval = setInterval(function() {
counter++;
chart.series[0].points[0].dataLabel.attr({
text: actualValue += step
});

if (counter > 10) {
clearInterval(dataLabelInterval);
}
}, 300);
}, 2000);

现场演示:https://jsfiddle.net/BlackLabel/01zfoyud/

关于javascript - Highcharts:与 setData 同步动态更新 dataLabels,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53990982/

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