Ajax is a web development technique that creates interactive Web applications. The following small series for you to share an AJAX dynamic assignment Echarts example (pie chart and column chart), has a very good reference value, I hope to be helpful to everyone. Let's take a look at it with a little knitting.
This paper is an example of dynamic assignment of Ajax in column and pie charts.
First, pie chart assignment steps
(1) JSP page
<!--introduced Echarts------<script src= "Js/echarts.js" ></script> <body> <!--to Echarts Prepare a DOM pie chart with size (wide height)---<p id= "first" style= "width:600px;height:400px;" ></p> [HTML] View plain copy</body>
(2) JS page
Pie chart template var dom = document.getElementById ("First"), var mychart = Echarts.init (DOM), var app = {};option = Null;option = { Title: {text: ' User location record ', Subtext: ', x: ' Center '}, tooltip: {trigger: ' item ', formatter : "{A} <br/>{b}: {C} ({d}%)"}, Legend: {Orient: ' Vertical ', x: ' Left ', data:[]}, to Olbox: {show:true, feature: {mark: {show:true}, DataView: {show:true, readonly:false}, Magictype: {show:true, type: [' pie ', ' funnel '], option: {funnel: { x: ' 25% ', Width: ' 50% ', funnelalign: ' Left ', max:1548} }}, restore: {show:true}, Saveasimage: {show:true}}}, Calculable:true, series : [{name: ', type: ' Pie ', radius: ' 55% ', center: [' 50% ', ' 60% '], data:[]} ] };; if (option && typeof option = = = "Object") {mychart.setoption (option, true);} Pie chart Dynamic Assignment var year = $ ("#year-search"). Val (); var mouth = $ ("#mouth-search"). Val (); $.ajax ({type: "Get", url:rootpath+ "/wxbound/getpiedatabymouth.action", Data: {"Year": Year, "Mouth": mouth} , Cache:false,//Disable cache DataType: "JSON", success:function (Result) {var names=[];//define two arrays var nums=[]; $.each (Result,function (key,values) {///Here I am returning list<string,map<string,string>> loop map Names.push (values. Province_name); var obj = new Object (); Obj.name = Values.province_name; Obj.value = Values.count; Nums.push (obj); }); Mychart.setoption ({//Load data graph legend: {Data:names}, series: { According to the name corresponding to the corresponding series name: [' Quantity '], data:nums}}); }, Error:function (XMLHttpRequest, textsTatus, Errorthrown) {alert ("Query failed"); } });
(3) Background code according to your own code is good
(4) Display style
Second, column chart assignment step
(1) JSP page
<!--introduced Echarts------<script src= "Js/echarts.js" ></script> <body> <!--to Echarts Prepare a DOM column with size (wide height)---<p id= "second" style= "width:600px;height:400px;" ></p> </body>
(2) JS page
Column chart template var domlong = document.getElementById ("second"); var Mychartsecond = Echarts.init (Domlong); var app = {};option = Nu Ll;option = {color: [' #3398DB '], tooltip: {trigger: ' axis ', Axispointer: {//Axis indicator, axis trigger valid Ty PE: ' Shadow '//default to line, Optional: ' Lines ' | ' Shadow '}, Grid: {left: ' 3% ', right: ' 4% ', bottom: ' 3% ', containlabel:true}, Xaxis: [ {type: ' Category ', data: [], Axistick: {alignwithlabel:true}}], YAxis: [{type: ' value '}], series: [{name: ' Direct Access ', type: ' Bar ', BarWidth: ' 60% ', Data:[]}]};if (option && typeof option = = = "Object") {mychartsecond.setoption (option, true);} Assign the column chart var year = $ ("#year-search"). Val (); $.ajax ({type: "POST", url:rootpath+ "/wxbound/getwxboundlist.action", Data: {"Year": Year}, Cache:f Alse,//Disable cache DataType: "JSON", success:function (Result) { Console.log (result); var linnames=[]; var linnums=[]; $.each (Result.lin,function (key,values) {Linnames.push (Values.mouth); Linnums.push (Values.count); }); Column Chart Assignment mychartsecond.setoption ({//Load data graph Xaxis: {data:linnames}, Series: {//According to the name corresponding to the corresponding series name: [' Quantity '], data:linnums}}); }, Error:function (XMLHttpRequest, Textstatus, Errorthrown) {alert ("Query failed"); } });}
(3) Backstage code part according to own need is good ...
(4) Picture Style
You can go and try your echarts icon ...
Above this Ajax dynamic assignment Echarts example (pie chart and column chart) is the small part to share all the content of everyone, hope to give you a reference, but also hope that we support the script home.
Related recommendations:
Ajaxupload.js example code to implement file upload
How to solve the Chinese garbled character of Ajax post data
An example of how to judge an AJAX request