首先引入amcharts.js(个人感觉饼图挺好用的)
我自己又写了一个简单的方法,传入三个参数(keyList,valueList,id),就生成比较cool的饼图。 /** * 生成饼图 * @param keyList * @param valueList * @param id * */ function createPie(keyList, valueList, id){ var sourceList = []; for(var i = 0; i < keyList.length; i++){ sourceList[i] = { key: keyList[i], value: valueList[i] } } AmCharts.ready(function(){ chart = new AmCharts.AmPieChart(); chart.dataProvider = sourceList; chart.titleField = "key"; chart.valueField = "value"; chart.outlineColor = "#FFFFFF"; chart.outlineAlpha = 0.8; chart.outlineThickness = 2;
chart.write(id); });}