<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>ECharts</title> <!-- 引入 echarts.js --> <script src="D:\echarts3\echarts.js"></script> <script src="D:\echarts3\roma.js"></script> <script src="D:\echarts3\jquery-3.1.1.min.js"></script> </head> <body> <!-- 为ECharts准备一个具备大小(宽高)的Dom --> <div id="main" style="width: 600px;height:400px;"></div> <script type="text/javascript"> // 初始化两个数组,盛装从数据库中获取到的数据 var wifi = [], count = [],time = []; //调用ajax来实现异步的加载数据 function getusers() { $.ajax({ type: "post", async: false, url: "http://localhost/lianjie.php", data: {}, dataType: "json", success: function(result){ if(result){ for(var i = 0; i < result.length; i++){ wifi.push(result[i].WIFIAPTag); count.push(result[i].passengerCount); time.push(result[i].timeStamp); } } }, error: function(errmsg) { alert("Ajax获取服务器数据出错了!"+ errmsg); myChart.hideLoading(); } }); return wifi, count,time; } // 执行异步请求 getusers(); // 基于准备好的dom,初始化echarts实例 var myChart = echarts.init(document.getElementById('main')); // 指定图表的配置项和数据 myChart.setOption({ title: { text: 'ECharts 入门' }, tooltip: {}, xAxis: { data: count } }) </script> </body> </html>
放到服务器的目录下运行:
修改后:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>ECharts</title> <!-- 引入 echarts.js --> <script src="D:\wamp64\www\echarts.js"></script> <script src="D:\wamp64\www\roma.js"></script> <script src="D:\wamp64\www\jquery-3.1.1.min.js"></script> </head> <body> <!-- 为ECharts准备一个具备大小(宽高)的Dom --> <div id="main" style="width: 600px;height:400px;"></div> <script type="text/javascript"> // 初始化两个数组,盛装从数据库中获取到的数据 var wifi = [], count = [],time = []; //调用ajax来实现异步的加载数据 function getusers() { $.ajax({ type: "get", async: true, url: "http://localhost/lianjie.php", data: {}, dataType: "json", success: function(result){ alert("Ajax获取服务器数据成功了!"+ errmsg); if(result){ for(var i = 0; i < result.length; i++){ wifi.push(result[i].WIFIAPTag); count.push(result[i].passengerCount); time.push(result[i].timeStamp); } } }, error: function(errmsg) { alert("Ajax获取服务器数据出错了!"+ errmsg); myChart.hideLoading(); } }); return wifi, count,time; } // 执行异步请求 getusers(); // 基于准备好的dom,初始化echarts实例 var myChart = echarts.init(document.getElementById('main')); // 指定图表的配置项和数据 myChart.setOption({ title: { text: 'ECharts 入门' }, tooltip: {}, xAxis: { data: time }, yAxis:{ data:count } }) </script> </body> </html>
慕的地6079101
紫罗天
慕仙5610752
東东4038330