0

我想让仪表图更新实时 dweet 数据,这是成功的。

问题是每次将新数据推送到数组湿度数据时,都会在量表中添加一个新指针,如下所示:量表 虽然我希望有一个实时更新指针。

这可以通过 pop() prev 数据来完成吗?

<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()

        });
4

1 回答 1

-1

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

于 2017-11-14T11:01:40.963 回答