【问题标题】:how to make chart real time with 2 line and get data from php with highcharts如何使用 2 行实时制作图表并使用 highcharts 从 php 获取数据
【发布时间】:2018-12-18 19:15:54
【问题描述】:

你好,我想用 php 制作图表来获取我的数据

这是我的脚本

 series: [{
            name: 'Random data',
            data: [<?php echo $row['rx-bits-per-second'] ?>]
        },
                {
            name: 'Random data',
            data: [<?php echo $row['tx-bits-per-second'] ?>]
        }]

这里有完整的脚本高图:

 $(document).ready(function() 
      {
        $('#dataTable').DataTable();
      });
</script>


<script>

$(function () {
    $(document).ready(function() {
        Highcharts.setOptions({
            global: {
                useUTC: false
            }
        });

        var chart;
        $('#container').highcharts({
            chart: {
                type: 'spline',
                animation: Highcharts.svg, // don't animate in old IE
                marginRight: 10,
                events: {
                    load: function() {

                        // set up the updating of the chart each second
                        var series = this.series[0];
                        var series2 = this.series[1];
                        setInterval(function() {
                            var x = (new Date()).getTime(), // current time
                                y = Math.random();
                                z = Math.random();
                            series.addPoint([x, y], false, true);
                            series2.addPoint([x, z], true, true);
                        }, 1000);
                    }
                }
            },
            title: {
                text: 'Live random data'
            },
            xAxis: {
                type: 'datetime',
                tickPixelInterval: 150
            },
            yAxis: [{
                title: {
                    text: 'Value1'
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080'
                }]
            },
            {
                title: {
                    text: 'Value2'
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080'
                }]
            }],
            tooltip: {
                formatter: function() {
                        return '<b>'+ this.series.name +'</b><br/>'+
                        Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+
                        Highcharts.numberFormat(this.y, 2);
                }
            },
            legend: {
                enabled: false
            },
            exporting: {
                enabled: false
            },
            series: [{
                name: 'Random data',
                data: [<?php echo $row['rx-bits-per-second'] ?>]
            },
                    {
                name: 'Random data',
                data: [<?php echo $row['tx-bits-per-second'] ?>]
            }]
        });
    });
});

并指向此处获取数据&lt;?php echo $row['tx-bits-per-second'] ?&gt;

但图表中的线条显示为空。你能帮帮我吗?

谢谢。

【问题讨论】:

  • 你能显示&lt;?php echo $row['tx-bits-per-second'] ?&gt;的输出吗?
  • 只输出随机数先生

标签: javascript php charts highcharts


【解决方案1】:

在那个“源”对象中,暂时删除 PHP 并添加简单的值,就像在 highcharts 示例中一样。在继续之前确保它是可靠的。

确定后,在 php 标记周围添加单引号,然后再试一次。

如果仍然有问题,我会在页面上执行“查看源代码”以检查该“源”对象数组中的“数据”属性是否已正确填充。 在不知道 PHP 是如何出现的情况下很难继续

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-16
    • 1970-01-01
    • 1970-01-01
    • 2017-02-12
    • 1970-01-01
    • 1970-01-01
    • 2012-10-12
    • 2014-07-04
    相关资源
    最近更新 更多