【问题标题】:how to dynamically change array in highchart?如何动态更改highchart中的数组?
【发布时间】:2014-10-27 12:10:23
【问题描述】:

这是我的系列数组。

var newData = [{
        name: 'All',
        data: myVar,
        grouping: false,
        zIndex: 1,
        color: '#999966',
        stack: 1,
        dataLabels: {
                enabled: true,

                shadow: false,

                useHTML: true,
                formatter: function() {
                   if (this.y != 0) return '<div class=\'amount\'>' + this.y + '</div>'; 
                },
                y: 0,

            },
    },{
        name: 'Negative',
        data: mySeries[0],
        grouping: true,
        zIndex: 2,
        color: '#FF3030',
        dataLabels: {
                enabled: true,

                shadow: false,

                useHTML: true,
                formatter: function() {
                    if (this.y != 0) return '<div class=\'amount\'>' + this.y + '<img src="img/neg.png"></div>'; 
                },
                y: 0
            },
    }, {
        name: 'Positive',
        data: mySeries[1],
        grouping: true,
        zIndex: 2,
        color: '#7ACC29',
        dataLabels: {
                enabled: true,

                shadow: false,

                useHTML: true,
                formatter: function() {
                    if (this.y != 0) return '<div class=\'amount\'>' + this.y + '<img src="img/pos.png"></div>'; 
                },
                y: 0
            },
    }
    ];

在配置中我指向这个数组。

series: newData,

问题:如何动态更改 highchart 以指向不同的数组?例如“旧数据”。 像这样:

 series: oldData,

提前致谢!

【问题讨论】:

    标签: javascript arrays highcharts


    【解决方案1】:

    你可以用series.update/setData代替它

    【讨论】:

    • 我在尝试 setData。但我确实需要保存属性。并深入到另一个情节并回到主情节。这个名为“newData”的数组是主要的。它有一个向下钻取的数据。例如在 myVar 中。我正在像这样向下钻取 [link]stackoverflow.com/questions/17004614/…
    • 谢谢!我使用 setData 对其进行了更改。但它的代码很大。是否可以制作每个系列的属性模式?
    • 应该是可能的,但是在 setData 你只有点数组,你有什么例子吗?我会更深入地检查它。
    • 看看link,有没有可能让这些非常非常糟糕的代码变得更好。我讨厌这个 goBack 功能 xD
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-11
    • 1970-01-01
    • 2021-03-25
    相关资源
    最近更新 更多