0

2 つのデータ ポイントを出力する php スクリプトを呼び出す ajax です

[エポックデータ、CPU]

ハイチャート ゲージ チャートを作成し、CPU 使用率を表示できるようにしたいと考えています。また、データ ラベルとして、php 呼び出しから取得した時間を表示したいと考えています。

function request_cpu_Data() {
    $.ajax({
        url: 'get_cpu.php', 
        success: function(data) {
        var myObj = JSON.parse(data); 
        var point = cpu_chart.series[0].points[0];
        var point1 = cpu_chart.series[1].points[0];
        var newVal=myObj[1];
        var newVal1=myObj[0];
        point.update(newVal);
        point1.update(newVal1);

        setTimeout(request_cpu_Data, 10000000); 
        },
        cache: false
    });
}

私のシリーズオプションは次のようなものです:

series: [{
            name: 'CPU',
            data: [0]

            },{
            name: 'Date',
            data: []
            }
        ]

このエラーが発生しています:

Uncaught TypeError: Cannot call method 'update' of undefined

これが第 2 シリーズの設定方法ですか。

var point1 = cpu_chart.series[1].points[0];
4

1 に答える 1

1

2 番目のシリーズにはデータが含まれていないため、cpu_chart.series[1].points は空の配列です。setData次のようにifを使用する必要がありますdata.lenght === 0

var secondSeries = chart.series[1];

if (secondSeries.data.length === 0) {
    secondSeries.setData([newValue]);
} else {
    secondSeries.points[0].update(newValue);
}

それがあなたを助けることを願っています。

于 2013-06-13T21:39:37.553 に答える