从 dweet 实时更新 highcharts-gauge

Live update highcharts-gauge from dweet

我想让仪表盘更新实时dweet数据,成功了。

问题是每次将新数据推送到数组 humidityData 时,都会在仪表图中添加一个新指针,如下所示: guage chart 虽然我想要一个实时更新指针。

这可以通过 pop() 上一个数据来完成吗?

<script language="JavaScript">

    //Array to store sensor data
    var humidityData = []

    <!--START-->
    $(document).ready(function() {
       //My Dweet thing's name
       var name = 'dweetThingName'

       //Humidity chart
       var setupSecondChart = function() {

       var chart2 = {
                type: 'gauge'
       };

       var title = {...};   

        var pane = {...};

       var yAxis = {...};

            var tooltip = {
                formatter: function () {
                    return '<b>' + "Humidity: "  + Highcharts.numberFormat(this.y, 2)  + "%";
                }
            }; 

            //Series_Humidity
            humiditySeries = [{
                name: 'Humidity %',
                data: humidityData, 
                    tooltip: {
                        valueSuffix: '%'
                    }
            }]

            //Json_Humidity
            var humJson = {}; 
            humJson.chart = chart2; 
            humJson.title = title; 
            humJson.tooltip = tooltip;
            humJson.xAxis = xAxis;
            humJson.yAxis = yAxis; 
            humJson.legend = legend; 
            humJson.exporting = exporting; 
            humJson.series = humiditySeries;
            humJson.plotOptions = plotOptions;

            console.log("Sereies: : " +humJson)
           //Container_Humidity
           $('#containerHumidity').highcharts(humJson);
        }

        var humiditySeries = []  ....

        dweetio.get_all_dweets_for(name, function(err, dweets){
            for(theDweet in dweets.reverse())
            {
                var dweet = dweets[theDweet];
                //Dweet's variables' names
                val2 = dweet.content["Humidity"]
                //Add the vals into created arrayDatas
                humidityData.push(val2)
                console.log("HumidityData: " + humidityData)
            }
           //Call other charts
           setupSecondChart()

        });

当您 initialize/update 您的图表时,请确保 data 数组仅包含一个元素。为该数组中的 每个 点创建刻度盘(以便在绘图上可视化)。