Echarts Dynamic Data loading via Ajax

Source: Internet
Author: User

  

One:
    <!--introduced echarts.js--    <script type= "Text/javascript" src= "Echarts.min.js" ></script>    < !--Introducing Jquery.js--    <script type= "Text/javascript" src= "Jquery-1.12.3.js" ></script>

Two:
<!--prepare a size (wide-height) Dom-to-    <div id= "main" style= "width:600px;height:400px for Echarts;" ></div>

Three:
function ShowView () {$ ("#view"). Show (); //initializing an Echarts instancevar mychart = echarts.init (document.getElementById (' View '))); //Show title, legend, and empty axesmychart.setoption ({title: {text:' Asynchronous Data loading example '}, tooltip: {}, Legend: {data:[' Number of registrations ']}, Xaxis: {data: []}, YAxis: { }, Series: [{name:' Number of registrations ', type:' Bar ', data: []}]});    Mychart.showloading (); //display a simple loading animation before the data is loadedvar names=[];//Date Array (actually used to hold x-axis coordinate values)var nums=[];//Register an array of numbers (actually used to hold the y-coordinate value)$.ajax ({type:"POST", DataType:"JSON", URL:"${pagecontext.request.contextpath}/back/customerdata/getviewlist.action", Success:function (data) {if(data.rows) { for(Var i=0;i<data.rows.length;i++) {Names.push (data.rows[i].registtime); //Take out the category and fill in the category array                             }                          for(Var i=0;i<data.rows.length;i++) {Nums.push (data.rows[i].registerday); //Take out the category and fill in the category array} mychart.hideloading (); //Hide Load AnimationsMychart.setoption ({//Load Data GraphXaxis: {data:names}, Series: [{//correspond to the corresponding series according to the nameName: ' Number of registrations ', data:nums}] })                    }Else{msgshow ("System Prompt", "Data query Error", "Warning");                         }                },            }); //display charts using the established configuration items and datamychart.setoption (option); }

Four: Background action

 Public voidGetviewlist ()throwsexception{String SQL= "Select Date_format (f.registdate, '%y-%m-%d ') as Registtime,count (F.flowingid) as Registerday" + " From Shop_invitation_flowerwater as F "+" GROUP by Registtime "; CustomerList=customerdataservice.findlistmapbysql (SQL); Map<string, object> jsonmap =NewHashmap<string, object> ();//Define MapJsonmap.put ("Rows", customerlist);//rows button to store a list of records per pageJsonconfig Jsonconfig =NewJsonconfig (); Jsonconfig.registerjsonvalueprocessor (Date.class,NewJsonformatdate ("Yyyy-mm-dd HH:mm:ss")); Jsonobject Jo= Jsonobject.fromobject (Jsonmap, jsonconfig);//formatting resultJo.accumulate ("Issuccess", "true"); Response.setcontenttype ("Text/html;charset=utf-8"); PrintWriter out=Response.getwriter ();        Out.println (Jo.tostring ());        Out.flush ();            Out.close (); }

Echarts Dynamic Data loading via AJAX

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.