Echarts AJAX Dynamic Fetch data

Source: Internet
Author: User
keys and values are Dynamic Data Note if the data is {value:335, Name: ' Direct access '} This format needs to use eval (' + Strtojson + ') ') to turn 
Load chart Start $ (function () {$.ajax ({//submit data type Post get type: "POST",//Submitted URL URL: "Http://localhost:8080/lightmanger/filemanager/fileDownload/fileDownloadPie", url: "<%=re
	            Quest.getcontextpath ()%>/filemanager/filedownload/filedownloadpie ",//Submit data data:{},
	            Returns the format of the data datatype: "HTML",//"XML", "HTML", "script", "JSON", "Jsonp", "text".             
	            The function called before the request Beforesend:function () {$ ("#msg"). HTML ("Lodding");},//function called after successful return
	                Success:function (Result) {result = $.parsejson (result);    var keys=[];    Class Array (actually used to hold the x-axis coordinate value) var values=[]; 
	                Sales array (actually used to hold the y-coordinate value var keysarray= new Array (); Keysarray=result.key.split ("#"); 
	          Character segmentation for (var i=0;i<keysarray.length; i++) {Keys.push (keysarray[i));      var valuesarray= new Array (); Valuesarray=result.value.split ("#"); 
	              	Character segmentation for (var i=0;i<valuesarray.length; i++) {Values.push (eval (' + valuesarray[i] + '));
	     		    var MyChart = echarts.init (document.getElementById (' Mainpie '));
		     		        option = {title: {text: ' Download volume from upgraded users ', subtext: ' Apk downloads ', X: ' Center '}, tooltip: {trigger: ' item ', formatter: ' {a} &L T;br/>{b}: {C} ({d}%) "}, Legend: {Orient: ' vertical ', le
		     		    FT: ' left ',//data:[' direct access ', ' mail marketing ', ' affiliate ads ', ' video ads ', ' search engine '] Data:keys},
		     		            Series: [{name: ' Download Times ', type: ' Pie ',
		 Radius: ' 55% ', center: [' 50% ', ' 60% '],    		           Data:values,/* [{value:335, Name: ' Direct Access '}, &nbsp ;                 {value:310,					Name: ' Mail Marketing '},                    {value:234, Name: ' affiliate AD '},                    {value:135, Name: ' Video ads '},          &nbs
		     		           p;        {value:1548, Name: ' Search Engine '}], * *
		     		                    ItemStyle: {emphasis: {shadowblur:10,
		     				            shadowoffsetx:0, Shadowcolor: ' Rgba (0, 0, 0, 0.5) '}
		     }
		     				        }				    ]
		     				};
	            mychart.setoption (option); },//Call function Complete:function (XMLHttpRequest, textstatus) {//alert after execution (XMLHT
	               Tprequest.responsetext);
	            alert (textstatus); },//Call function Error:function () {//Request error handling}})
	;
	}); Load Chart End

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.