试图动态更新Highchart柱形图,但系列未定义 [英] trying to dynamically update Highchart column chart but series undefined

查看:81
本文介绍了试图动态更新Highchart柱形图,但系列未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用服务中的新信息更新现有的highcharts柱形图。我正在尝试通过在系列中使用setdata方法来完成此操作,但是系列中的未定义。我对这种类型的编程非常陌生,所以我不理解我做错了什么。
任何帮助将不胜感激。
我的代码如下:

I am trying to update an existing highcharts column chart with new information from a service. I am trying to do this by using the setdata method on the series but the series in "undefined". I am very new to this type of programming so I have no ideal what I am doing wrong. Any help would be greatly appreciated. My Code is below:

$('#chart22').highcharts({
    colors: ['#FBB369', '#7798BF'],
chart: {
    type: 'column'
},
title: {
    text: 'Some Data'
},
xAxis: {
    categories: ['Cat1', 'Cat2']

},
yAxis: {
    title: {
        text: 'Amount'
    },
    labels: {
        formatter: function() {
            return this.value / 1000000000 +'B';
        }
    }
},
credits: {
    enabled: false
},
exporting: { 
    enabled: false 
},
series: [{
    name: 'Amount',
    data: [-3450000000.25, 3670000000.35]

   }]
});


setInterval(function() { getData(); }, 30000);


function getData(){

    console.log("retrieving data from server ");
    var url = "http://localhost/someserver call";

    $.getJSON (url, function (Data44) {
        var data = data44; //we are good here

        // update the series data

        chart22.series[0].setData(data);
        chart22.series.setData(data);  //both give the error that series is undefined ????

    });
}


推荐答案

您尚未创建变量 chart22 所以毫不奇怪,属性是未定义的。

You haven't created the variable chart22 so it's no surprise that properties are undefined.

试试这个

var timerId = setInterval(function() {
    console.log("retrieving data from server ");
    var url = "http://localhost/someserver call";

    $.getJSON(url, function(data) {
        $('#chart22').highcharts().series[0].setData(data);
    });
}, 30000);

JSFiddle demo Series.setData 应该已经向您显示了要做的事情。

The JSFiddle demo for Series.setData should have shown you exactly what to do.

这篇关于试图动态更新Highchart柱形图,但系列未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆