Heim >Backend-Entwicklung >PHP-Tutorial >Verwenden Sie php+ajax+echarts.js, um ein statistisches Antwortkurvendiagramm pro Minute zu implementieren
Im Anschluss an den vorherigen Blog habe ich neben der Implementierung statistischer Gesamtsummen auch Baidus Echart verwendet, um statistische Antwortkurven zu implementieren. Der Effekt ist wie folgt: http://newer.gailvlunpt.com/EntranceEducation/admin.php/Statis/index
Baidu echart ist eine professionelle JS-Bibliothek eines Drittanbieters für statistische Diagramme und Kurvendiagramme. Die Anwendung ist gemäß der Anleitung recht einfach.
Der Quellcode lautet wie folgt
Der Front-End-HTML+JS+CSS-Code lautet wie folgt
{__NOLAYOUT__} <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <!-- 引入 ECharts 文件 --> <script src="__PUBLIC__/admin/js/echarts.common.min.js"></script> <script src="__PUBLIC__/admin/js/jquery.min.js"></script> </head> <body> <!-- 为 ECharts 准备一个具备大小(宽高)的 DOM --> <p id="main" style="width: 1400px;height:600px;"></p> <a href="{:U('sum')}" target="_blank">实时统计平台答题总量</a> </body> </html> <script type="text/javascript"> var myChart = echarts.init(document.getElementById('main')); option = { title : { text: '过去3小时答题情况', subtext: '浙江工商大学新生事业教育平台试试答题数据' }, tooltip : { trigger: 'axis' }, legend: { data:['过去3小时答题量'] }, calculable : true, xAxis : [ { type : 'category', boundaryGap : false, data : [] } ], yAxis : [ { type : 'value', axisLabel : { formatter: '{value}' } } ], series : [ { name:'实时答题统计', type:'line', data:[], }, ] }; // 使用刚指定的配置项和数据显示图表。 url = "{:U('Statis/data')}"; myChart.setOption(option); // url = 'http://newer.gailvlunpt.com/EntranceEducation/admin.php/Statis/data'; $.get(url).done(function (data) { // 填入数据 myChart.setOption({ xAxis: { data: data.x_data }, series: [{ // 根据名字对应到相应的系列 data: data.y_data }] }); }); setInterval(function () { $.get(url).done(function (data) { // 填入数据 myChart.setOption({ xAxis: { data: data.x_data }, series: [{ // 根据名字对应到相应的系列 data: data.y_data }] }); }); }, 60000); //一秒钟统计一次 </script>
Der Hintergrund-PHP-Code
public function data() { $now = time(); // $timeArray = new array(); for($i=1;$i<=180;$i++){ $time = $now - 3 * 60 * 60 + 60 * $i; $timeArray[] = date('Y-m-d H:i', $time); $map['time'] = array('between',array(date('Y-m-d H:i', $time),date('Y-m-d H:i', $time+60))); $dataArray[] = D('Exercise')->where($map)->count(); } $data = array( 'x_data'=>$timeArray, 'y_data'=>$dataArray ); $this->ajaxReturn($data); }
verwendet Minuten pro Zeit als Abszisse und die Menge der Antwortdaten als Ordinate Zeichne ein Diagramm
Das obige ist der detaillierte Inhalt vonVerwenden Sie php+ajax+echarts.js, um ein statistisches Antwortkurvendiagramm pro Minute zu implementieren. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!