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

标签 javascript highcharts

我想与 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/

相关文章:

javascript - 如何访问 AngularJS 指令元素索引

javascript - jquery动态添加<li>时不出现滚动条

Highcharts:当 styledMode 打开时,设置线条系列上的描边宽度没有效果

javascript - 使用 Highcharts 显示 S0-Ticks

javascript - 模态确认删除 - 不起作用

javascript - 使用参数创建函数搜索对象数组

javascript - 工具提示 d3js 面积图中的 roi 值

javascript - Highcharts 绘图标记在样条图动画后面移动

javascript - 将构建数组的 PHP 代码转换为 JS,现在 highcharts 不起作用 - 我做错了什么?

javascript - Highcharts 日期解析问题