weixin_43941237
weixin_43941237
2018-12-06 06:13

highcharts怎么后台查询数据库赋值到前台

  • java
  • highcharts
  • js
  • 数据库
<script type="text/javascript">
Highcharts.chart('container1', {
    chart: {
        type: 'spline',
        animation: Highcharts.svg,
        marginRight: 10,
        backgroundColor: '#f8f8f8',
        type: 'line',
        events: {
            load: function () {
                //设置更新
                var proR_id = $("#proR_id").val();
                var series = this.series[0];
                setInterval(function () {

                    $.ajax({
                        url:"/HighSupportModel/detectionEngineering/selectShishi?proR_id="+proR_id,
                        type:"post",
                        dataType:"json",
                        success : function(data){
                            for(var i=0;i<data.length;i++){
                                alert(data[i].test_date1);
                                 var x = (new Date()).getTime(), // 当前时间
                                //y = Math.random();
                                y = data[i].test_date1;
                                series.addPoint([x, y], true, true);
                            }
                        }
                    });
                }, 3000);
            }
        }
    },
    credits : {
        enabled: false
    },
    time: {
        useUTC: false
    },
    title: {
        text: '立杆倾斜曲线'
    },
    xAxis: {
        type: 'datetime',
        tickPixelInterval: 150
    },
    yAxis: {
        title: {
            text:''
        },
        plotLines: [{
            value: 0,
            width: 1,
            color: '#808080'
        }]
    },
    tooltip: {
        headerFormat: '<b>{series.name}</b><br/>',
        pointFormat: '{point.x:%Y-%m-%d %H:%M:%S}<br/>{point.y:.2f}'
    },
    legend: {
        enabled: false
    },
    exporting: {
        enabled: false
    },
    series: [{
        name: '数据',
        data: (function () {
            // generate an array of random data
            var data = [],
                time = (new Date()).getTime(),
                i;
            for (i = -19; i <= 0; i += 1) {
                data.push({
                    x: time + i * 1000,
                    y: Math.random()
                });
            }
            return data;
        }())
    }]
});
</script>

我这里数据可以接收到 alert有值 但就是add不进去
自己瞎写了点 不太明白 提前谢谢大佬回答!
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐