Ajax从数据库取值到echarts,提示[object object],请问哪里的问题

浏览:1113 发布日期:2018/07/25 分类:求助交流 关键字: Ajax tp5 前端 echarts
控制器public function humi()
    {
        $humi = \think\Db::table('Data_Info')
                ->alias('a')
                ->join('Device_Info e','a.Did = e.id','LEFT')
                ->where('a.Datatype','=','0x02')
                ->field('e.DName,a.DataValue,a.DataTime,a.id')
                ->paginate(5);
        $data= \think\Db::table('Data_Info')
                ->where('Datatype','=','0x02')
                ->select();
        $this->assign('humi',$humi);
        $sqldata1[0]['DataValue']=$data[0]['DataValue'];
            $sqldata1[0]['DataTime']=$data[0]['DataTime'];
        // for ($i=0; $i < count($data) ; $i++) {
            // alert(JSON.stringify(data[1]));
            // $sqldata1[$i]['DataValue']=$data[$i]['DataValue'];
            // $sqldata1[$i]['DataTime']=$data[$i]['DataTime'];
        // }

        $sqldata_json=json_encode($sqldata1);


        echo  $sqldata_json;
        return $this->fetch();
    }
Ajax部分+echerts部分<script type="text/javascript">
        var myChart = echarts.init(document.getElementById('main'));
            var arr1=[] , arr2=[];
    function getusers() {
        $.ajax({
            type: "post",
            async: false,
            url: "dataman/humi",
            data: {},
            dataType: "json",
            success: function(result){
                if(result){
                          var arr1=[] , arr2=[];
                          for (var i = 0; i < result.length; i++) {
                              return a=1;
                              arr1.push(result[i].DataValue);
                              arr2.push(result[i].DataTime);
                          }
                }
            },
            error: function(errmsg) {
                alert("Ajax获取服务器数据出错了!"+ errmsg);
            }
        });
        return arr1, arr2;
    }
    getusers();

    option = {
            title : {
                text: '湿度检测图',
                <!-- subtext: '纯属虚构' -->
            },
            tooltip : {
                trigger: 'axis'
            },
            legend: {
                data:['湿度']
            },
            toolbox: {
                show : true,
                feature : {
                    mark : {show: true},
                    dataView : {show: true, readOnly: false},
                    magicType : {show: true, type: ['line', 'bar']},
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            calculable : true,
            xAxis : [
                {
                    type : 'category',
                    boundaryGap : false,
                    data : arr1
                }
            ],
            yAxis : [
                {
                    type : 'value',
                    axisLabel : {
                        formatter: '{value} °C'
                    }
                } 
            ],
            series : [
                {
                    "name":'湿度',
                    "type":'line',
                    "data":arr2,
                    markPoint : {
                        data : [
                            {type : 'max', name: '最大值'},
                            {type : 'min', name: '最小值'}
                        ]
                    },
                    markLine : {
                        data : [
                            {type : 'average', name: '平均值'}
                        ]
                    }
                }
            ]
        };
        
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    

        </script>
查了一下说要把数据转成json,应该怎么做
最佳答案
评论( 相关
后面还有条评论,点击查看>>