Echart and PHP for Dynamic Data acquisition

Source: Internet
Author: User
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);? 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.