This article is mainly to share with you echart and PHP dynamic access to data implementation method, if the following code does not work, please refer to the comments section, I hope to help everyone.
HTML part of the code
JS part of the code
<script> var chart = echarts.init (document.getElementById (' main ')); Chart.setoption ({title:{text: ' Asynchronous Load ',}, tooltip: {}, legend:{data:[' sales '],}, Xaxi s:{data:[],}, yaxis:{}, series:[{name: ' Sales ', type: ' Bar ', data:[]}]}); var categories = [], data = []; /* Note {: URL ()} This piece fills in the address you want to request you can be http://.....com or you can be a piece of file in your project index/index*/$.post ("{: url (' Ticket/getsellrecord ', [' Type ' = ' + ' Week ')} '). Done (info) {//Fill in Data/* Special note here if info is a JSON object you don't have to json.parse if it's a JSON string, it's going to be an object */cons Ole.log (info); info = json.parse (info); for (var i = 0; i < info.length; i++) {Categories.push (info[i][' seller_id ']); Data.push (info[i][' amount '); } chart.setoption ({xaxis: {data:categories}, Series: [{//corresponds to the corresponding series by name Name: ' Sales ', Data:data}]}); </script>
PHP section Code
<?php/* You can set a fixed value to test, the dynamic is you to get this part of the database is the main format */* Return Data format for JSON in JS print the past number JSON string or JSON object if it is a JSON string be sure to turn it into a JSON object available Json.parse */$data = [["seller_id" =>2, "Amount" = "],[" seller_id "=>8," Amount "=" 501 "]; Return Json_encode ($data);?