PHP uses Echarts to generate data statistics report implementation code, echarts data statistics
Echarts statistics, simple example
Let's take a look at it first.
Check the code
The HTML page prepares a Dom for ECharts, Which is customized in width and height.
<div class="panel panel-info"> <div class="panel-body"> <div id="echart_show" style="height:500px"></div> </div></div>
For js files, refer to the official website or download and introduce them here.
<Script type = "text/javascript" src = "_ ROOT _/Public/admin/lib/jquery/nowdatachars/echarts-all.js"> </script>
The following are the specific methods:
<Script type = "text/javascript"> var date = [], num = []; $ (document ). ready (function () {// draw the feedback graph var init_echarts = function () {var refreshChart = function (show_data) {my_demo_chart = echarts. init (document. getElementById ('echart _ show '); my_demo_chart.showLoading ({text:' loading... ', effect: 'whirling'}); var echarts_all_option = {title: {text: '', subtext: 'user trending'}, tooltip: {trigger: 'axis '}, legend: {data: ['users', 'user consumable ']}, toolbox: {show: true, feature: {mark: {show: true}, dataView: {show: true, readOnly: false}, magicType: {show: true, type: ['line', 'bar']}, restore: {show: true}, saveAsImage: {show: true} // myTool2: {// show: true, // title: 'custom extension method', // icon: 'image: // http://echarts.baidu.com/images/favicon.png', // onclick: function () {// alert ('custom') //} // }}}, dataZoom: {show: false, start: 0, end: 100}, xAxis: [{type: 'category ', boundaryGap: true, data: show_data [1]}, {type: 'category', boundaryGap: true, data: show_data [1]}], yAxis: [{type: 'value', scale: true, name: 'user', boundaryGap: [0, 0.5] // boundaryGap: [0.2, 0.2]}, {type: 'value', scale: true, name: 'user', boundaryGap: [0, 0.5]}], series: [{name: 'user consumable ', type: 'bar', xAxisIndex: 1, data: show_data [0]}, {name: 'users', type: 'line', xAxisIndex: 1, data: show_data [0]}; my_demo_chart.hideLoading (); my_demo_chart.setOption (echarts_all_option);}; // get original data $. ajax ({url: "_ CONTROLLER _/getRes", async: false, dataType: 'json', type: 'post', success: function (msg) {var result = msg. result; if (msg. code = 200) {for (var I = 0; I <result. length; I ++) {date. push (result [I]. date); num. push (result [I]. count); msg [0] = num; msg [1] = date; refreshChart (msg );}}}});}; // var default_load = (function () {init_echarts () ;}) is loaded by default; </script>
Query the data you need in the Controller (the date and quantity of the query here)
// Collect the public function getRes () {$ user = M ('account'); $ SQL = "SELECT date (createTime) AS date, count (*) as count FROM t_account group by date "; $ result = $ user-> query ($ SQL); $ this-> ajaxReturn (array ('code' => 200, 'result' => $ result ));}
So far, a simple echarts Statistical Chart is available.
I am not familiar with some parameters in echarts. For details, refer to the Echarts Documentation website.