In doing a project that needs to be used on a echarts map, it was successful to get the data in the background with Ajax and generate the desired JSON string. But, put in Echarts option.series[0].data, get no data. You can't see the values you get from the background on the generated map. Baidu and Bing, the answer to the wide variety of answers, still unresolved problems, and finally a colleague Daniel to solve, here to share with you. Hope to be helpful to you,,,,
Nonsense not much to say, directly on the code:
$ (function () {var data = []; function setOption (data) {var MyChart = Echarts.init (document.getElementById (' main '));
Window.onresize = mychart.resize; var option = {title: {text: ' National ... Distribution map ',//subtext: ' Purely fictitious ', X: ' Left '}, tooltip: {trigger: ' item '},//legend: {//Orient: ' Vertical ',//x: ' Left ',//D ata:[' Iphone3 ', ' iphone4 ', ' iphone5 '//}, DataRange: {min:0, max:10, x: ' Left ', y: ' Bottom ', text:[' high ', ' low '],//text, default number Value text color:[' #ff5e5e ', ' #ffa25e ', ' #ffd05e ', ' #fce6b2 ', ' #e1dbcd '], calculable:true},//Toolbox: {//Show:true,//Orie NT: ' vertical ',//x: ' Right ',//y: ' center ',//feature: {//Mark: {show:true},//DataView: {show:true, readOnly : false},//restore: {show:true},//Saveasimage: {show:true}//}//},//Roamcontroller: {//Show:true,//x: ' R Ight ',//Maptypecontrol: {//' country ': TRUE//}//}, Series: [{name: ' ... ', type: ' Map ', Maptype: ' Country ', Roam:fal SE, itemstyle:{normal:{label:{show:true}}, Emphasis:{label:{show:true}},
Data:data}]};
mychart.setoption (option); $.getjson (' Hotspotservlet ', function (data) {//option.series[0].data=data.result;//Load data for Echarts object//
mychart.setoption (option);
//}); }//Get ...
The ranking data function Getmapdata (limit) {$.ajax ({url: ' http://127.0.0.1/api/adminunit/score/top/' +limit, type: ' Post '), DataType: ' JSON ', success:function (objdata) {//var str = json.parse (objdata); for (var i = 0;i < Objdata.length;i + +) {VA
R dId = parseint (objdata[i].id);
var dname= "Tianjin";
if (did==1) {//Dname= "Beijing";//} var dname = Objdata[i].name;
var dscore = parseint (Objdata[i].score);
var onedata = {};
var onedata = {Id:did,name:dname,value:dscore};
Data.push (Onedata);
} console.log (data);
Option.series[0].data=data; SetOption (data);//execute setOption function.
Argument}});
} getmapdata (2); });
The most important thing is that the data obtained from the backstage is put into the echarts through the form of reference.
At that time, when I did not pass the form of the argument, the data obtained in the echarts is always empty.