/*
*@data: series中的data数据
*@legend:图例数据
*@name: 标题
*/
function pieCharts(data, legend,name) {
//计算data中value的总和
var a = 0;
for (var i = 0; i < data.length; i++) {
a += parseFloat(data[i].value);
}
//添加新的元素到data中,并设置其颜色样式为白色
data.push({ value: a, name: '__other', itemStyle: { normal: { color: 'rgba(0,0,0,0)' } } });
let option = {
color: ['rgba(84,127,229,1)', 'rgba(54,195,155,1)', 'rgba(167,140,222,1)', 'rgba(38,198,217,1)', 'rgba(238,110,115,1)', 'rgba(254,178,116,1)'],
tooltip: {
trigger: 'item',
backgroundColor: 'rgba(255,255,255,0.7)',
padding: 0,
extraCssText: 'box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.3);',
formatter: function (param) {
if (param.name != '__other') {
var str = '<style>td{padding:5px;}</style><table>';
var c = (param['value']/a)*100;
c = c.toFixed(2);
str = str + c + "%";
return str
} else {
return
}
}
},
legend: {
icon: 'pin',
itemWidth: 14,
itemHeight: 5,
orient: 'horizontal',
top: 40,
data: legend,
},
grid: {
height: '210px',
top: '-10%',
left: '-20%',
right: '7%',
containLabel: true
},
series: [
{
name: name,
type: 'pie',
startAngle: 180,
radius: ['62%', '90%'],
center: ['50%', '82%'],
data: data,
itemStyle: {
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
},
label: {
normal: {
show: false,
},
emphasis: {
textStyle: {
fontSize: '30',
fontWeight: 'bold'
}
}
},
labelLine: {
normal: {
show: false
}
},
}
]
}
return option
}