Echarts Circular pie chart dynamically get JSON data

Source: Internet
Author: User

Echarts Circular pie chart dynamically get JSON data

As follows:


I. HTML section

<div id= "Secondpiechart" style= "width:100%; height:400px; " ></div>

Two. js section

<script type= "Text/javascript" >

function Loadonecolumn () {
var mychart = echarts.init (document.getElementById (' Secondpiechart '));
Show title, legend, and empty axes
Mychart.setoption ({
Color: [' #ff7d27 ', ' #47b73d ', ' #fcc36e ', ' #57a2fd ', ' #228b22 '],//pie chart colors
Title: {
Text: "Ranking of information release",
Subtext: ' Pure fiction ',
X: ' Center '
},
ToolTip: {
Trigger: ' Item ',
Formatter: "{A} <br/>{b}: {C} ({d}%)"
},
Legend: {
Orient: ' Vertical ',
x: ' Left ',
Data: []
},
Toolbox: {
Show:true,
Feature: {
Mark: {Show:true},
DataView: {show:true, readonly:false},
Magictype: {
Show:true,
Type: [' pie ', ' funnel '],
Option: {
Funnel: {
x: ' 25% ',
Width: ' 50% ',
Funnelalign: ' Center ',
max:1548
}
}
},
Restore: {show:true},
Saveasimage: {show:true}
}
},
Calculable:true,
Series: [{
Name: ' Published rankings ',
Type: ' Pie ',
Radius: [' 50% ', ' 70% '],//Set the space size of the ring
ItemStyle: {
Normal: {
Label: {
Show:true
},
Labelline: {
Show:false
}
},
Emphasis: {
Label: {
Show:true,
Position: ' Center ',
TextStyle: {
FontSize: ' 20 ',
FontWeight: ' Bold '
}
}
}
},
Data: []
}]
});
Mychart.showloading (); Display a simple loading animation before the data is loaded
var names = []; Category Array (the category used to store the pie chart)
var brower = [];
$.ajax ({
Type: ' Get ',
URL: ' Json/chart/column/index_fbph.txt ',//address of request data
DataType: "JSON",//return data in the form of JSON
Success:function (Result) {
The function contents are executed when the request succeeds, and result is the JSON object returned by the server
$.each (result.list, function (index, item) {
Names.push (item.department); Take out the category and fill in the category array
Brower.push ({
Value:item.num,
Name:item.department
});
});
Mychart.hideloading (); Hide Load Animations
Mychart.setoption ({//Load data graph
Legend: {
Data:names
},
Series: [{
Data:brower
}]
});
},
Error:function (errormsg) {
Execute the function when the request fails
Alert ("Chart request data failed!");
Mychart.hideloading ();
}
});
};
Loadonecolumn ();
</script>

Three. The JSON format is as follows:

{"List": [{"Department": "Heping", "num": 480},{"department": "Hexi District", "num": 380},{"department": "Hedong", "num": 366},{" Department ":" Hebei District "," num ": 320},{" department ":" Nankai District "," num ": 300}]}

Echarts Circular pie chart dynamically get JSON data

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.