Background PHP write, to the foreground to prepare JSON format data
Public Function Actiongetoffline () {$userid = Yii:: $app->user->identity->user_id; $connection = Yii:: $app->db; $command = $connection->createcommand ("Select proc_phase_id from Tb_pro where user_id like '% $userid% ';"); $data = $command->queryall (); Var_dump ($data); Die (); $count = Array (0,0,0,0,0,0,0); foreach ($data as $value) {foreach ($value as $value 1) {switch ($value 1) {case 0: $count [0]= $count [0]+1; Break Case 1: $count [1]= $count [1]+1; Break Case 3: $count [2]= $count [2]+1; Break Case 6: $count [3]= $count [3]+1; Break Case: $count [4]= $count [4]+1; Break Case: $count [5]= $count [5]+1; Break Case: $count [6]= $count [6]+1; Break }}} $res = Array (' countdata ' = = $count); //Var_dump ($res); Die (); Return Json_encode ($res); }
The JSON data format is as follows: foreground echarts histogram shows that the data is obtained via Ajax:
Finally, the dynamic loading of the data to Echarts is successful, a simple small example:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Echarts Ajax dynamically loading JSON data