PHP and MySQL with Ajax and Echart synthesis

Source: Internet
Author: User
Tags php and mysql

Http://www.yinghualuowu.com/php/echart.html

CREATE TABLE sex with Name num

<?PHPIni_set(' Display_errors ', 1);//error Message    Ini_set(' Display_startup_errors ', 1);//PHP startup error message    error_reporting(-1); Ini_set(' Error_log ',dirname(__file__) . '/error3_log.txt ');//Print out all the error messages    require("config.php"); $conn=Mysqli_connect($mysql _server_name,$mysql _username,$mysql _password) or die("Error Connecting"); Mysqli_query($conn, ' Set names UTF8 '); mysqli_select_db($conn,$mysql _database); $result=Mysqli_query($conn, "SELECT * from Sex"); $data=""; $array=Array(); classuser{ Public $name;  Public $num; }      while($row=Mysqli_fetch_array($result,Mysqli_assoc)) {        //printf ("%s:%s", $row ["name"], $row ["num"]);         $user=NewUser (); $user->name=$row[' Name ']; $user->num=$row[' Num ']; $array[]=$user; }    $data=json_encode ($array); Echo $data;?>

In this way, we create a JSON file

<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><title>Untitled Document</title><Scriptsrc=".. /js/echarts.min.js "></Script><Scriptsrc= "Https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></Script></Head><Body><DivID= "Main"style= "height:400px"></Div><Scripttype= "Text/javascript">              varMyChart=Echarts.init (document.getElementById ('Main')); vararr1=[],ARR2=[]; functionarrtest () {$.ajax ({type:"Post", URL:"echart.php", DataType:"JSON", Async:false, data:{}, Success:function(Result) {if(Result) { for (varI= 0; I<result.length; I++) {Arr1.push (result[i].name);                      Arr2.push (Result[i].num); }}}, error:function(errormsg) {alert ("Data read failed"); }                      })                returnarr1,arr2;                } arrtest (); Console.log (arr1[0]); varoption={tooltip: {show:true}, Legend: {data:['Num']}, Xaxis: [{type:'category', DATA:ARR1}], YAxis: [ {type:'value'}], series: [{ "name":"Num",                            "type":"Bar",                            "Data": arr2}]                };       mychart.setoption (option); </Script></Body></HTML>

PHP and MySQL with Ajax and Echart synthesis

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.