简体   繁体   English

如何用实时数据更新Highcharts?

[英]How to update Highcharts with live data?

I've been looking for several days at various options for updating Highcharts data. 我一直在寻找用于更新Highcharts数据的各种选项的几天。 All I have tried has not worked and I know it's my lack of programming skills that is stopping me. 我所尝试的一切都没有奏效,我知道我缺乏编程技能阻止了我。 I've read the documentation in Highcharts but it doesn't give an example for calling a php file within a standard script but shows a randonm data generator! 我已经阅读了Highcharts中的文档,但它没有给出在标准脚本中调用php文件但是显示randonm数据生成器的示例!

Could someone help. 有人可以帮忙吗

I have a floor plan that has items that change colour based on a desk being occupied or unoccupied. 我有一个平面图,其中的项目根据桌面被占用或未被占用而改变颜色。 I'm using a PHP file to pull the data from an MSSQL server and it updates with the latest data when I refresh the page. 我正在使用PHP文件从MSSQL服务器提取数据,并在刷新页面时使用最新数据进行更新。

在此输入图像描述

I would like to update the information every 5 seconds if possible but only update the data points not the page. 我想尽可能每5秒更新一次信息,但只更新数据点而不是页面。 I have other charts where I want to do the same thing. 我有其他图表,我想做同样的事情。

Here is the chart code: 这是图表代码:

<script type="text/javascript">  // PLAN INDICATING OCCUPIED OR UNOCCUPIED DESKS
        $(function() {
    $('#chart1').highcharts({
        chart: {
            plotBackgroundImage: '/Highcharts/graphics/HSSMIPLAN.png',
            height: 600,
            animation: false
        },

        credits: {
            enabled: false
        },

        title: {
        text: null      //'HSSMI Occupancy Plan (Live)'
    },

        xAxis: {
        min: 0,
        max: 1000,
        labels: {enabled:false},
        lineColor: 'transparent',
        minorTickLength: 0,
        tickLength: 0
    },

        yAxis: {
        min: 0,
        max: 600,
        title: false,
        gridLineWidth: 0,
        labels: {enabled:false},
        lineColor: 'transparent',
    },

    legend: {
            enabled: false
        },

    plotOptions: {
        series: {
            cursor: 'ns-resize',
            point: {
                events: {
                    drag: function (e) {
                        $('#drag').html(
                            'Dragging <b>' + this.series.name + '</b>, <b>' + this.category + '</b> to <b>' + Highcharts.numberFormat(e.newY, 0) + '</b>');
                    },
                    drop: function () {
                        $('#drop').html(
                            'In <b>' + this.series.name + '</b>, <b>' + this.category + '</b> was set to <b>' + Highcharts.numberFormat(this.y, 0) + '</b>');
                    }
                }
            },
            //stickyTracking: false
        },

    },

    tooltip: {
            borderColor: 'rgb(43, 110, 151)',
            formatter: function () {
                return 'Sensor: <b>'+ this.point.name + '</b><br>X Value: <b>' +
                    this.point.x + '<br>Y Value: <b>' + this.point.y +'</b>';
            }
        },

    series: [{
        type: 'bubble',
        minSize: 25,
        maxSize: 25,
        cursor: 'pointer',
        draggableX: false,
        draggableY: false,
        data: [<?php echo $data12a?>]
        }]

    });


$('#getcsv').click(function () {
    var csv = "Series;Name;X;Y\n";
    $.each(Highcharts.charts[0].series, function(i,s){
        $.each(s.points, function(j,p){
            csv += s.name + ";" + p.name + ";" + p.x + ";" + p.y + "\n";
        });
    });
    alert(csv);
});

});

        </script>

I've been looking at various option but not sure where or how to add the code to the existing script. 我一直在寻找各种选项,但不确定在何处或如何将代码添加到现有脚本中。

I saw this for updating a table and thought it may be close to what I need: 我看到这个更新表并认为它可能接近我需要的:

<script type="text/javascript">
    $(document).ready(function(){
      refreshTable();
    });

    function refreshTable(){
        $('#tableHolder').load('getTable.php', function(){
           setTimeout(refreshTable, 5000);
        });
    }
</script>

As always any help you can give would be appreciated. 一如既往,您可以给予任何帮助,将不胜感激。

Thanks Rob 谢谢Rob

使用方法setData Highcharts - setData

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM