<body>
<div id="lamp" style="height: 174px;"></div>
<div id="landscape" style="height: 174px;"></div>
<div id="saving" style="height: 208px;"></div>
<script src="echarts.min.js"></script>
<script type="text/javascript">
var lampOpenCount =3;
var convertCtrlOpen=1;
var saveEnergy=1;
var lampCount=2;
var convert=2;
var noIntelLight=4;
drawPieChart('lamp', 1,lampOpenCount,lampCount);
drawPieChart('landscape', 1,convertCtrlOpen,convert);
drawPieChart('saving', 2,saveEnergy,noIntelLight);
function drawPieChart(id, type,openCount,count) {
var myChart = echarts.init(document.getElementById(id));
var option = {
tooltip: {
show: false
},
legend: {
show: false
},
color: ['#efae25', '#f0f2f5'],
series: [{
name: type === 1 ? '亮灯率' : '节电率',
type: 'pie',
radius: type === 1 ? ['60%', '80%'] : ['48%', '68%'],
center: ['50%', '50%'],
hoverAnimation: false,
avoidLabelOverlap: false,
label: {
normal: {
position: 'center',
textStyle: {
fontSize: '16',
color: '#999'
},
formatter: "{a} \n {d}%"
}
},
labelLine: {
normal: {
show: false
}
},
data: [{
value: openCount,
label: {
normal: {
show: true
}
},
itemStyle: {
emphasis: {
color: '#efae25'
}
},
},
{
value: count-openCount,
label: {
normal: {
show: false
}
},
itemStyle: {
emphasis: {
color: '#f0f2f5'
}
}
}
]
}]
};;
if (option && typeof option === "object") {
myChart.setOption(option, true);
}
}
</script>
</body>