<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
list-style: none;
}
.circleWrap {
overflow: hidden;
}
.circleWrap .circle {
/* float: left; */
width: 200px;
float: left;
}
</style>
</head>
<body>
<div class="circleWrap">
<div id="lamp" style="height: 174px;" class="circle"></div>
<div id="landscape" style="height: 174px;" class="circle"></div>
<div id="saving" style="height: 208px;" class="circle"></div>
</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', 3, 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 ? '亮灯率' : '节电率',
name: type === 1 ? '亮灯率' : type === 2 ?'节电率':type === 3?'自定义':'',
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>
</html>