<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
#chart-panel {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
width: 1000px;
height: 750px;
}
</style>
<script src="./lib/5.5.0/echarts.min.js"></script>
</head>
<body>
<div id="chart-panel"></div>
<!-- 为ECharts准备一个具备大小(宽高)的Dom -->
<script type="text/javascript">
//初始化图表对象。
var myChart = echarts.init(document.getElementById('chart-panel'), "dark");
//图表配置。
let colors = ["rgba(133, 246, 122, 1)", "rgba(240, 113, 255, 1)", "rgba(253, 81, 81, 1)", "rgba(123, 44, 255, 1)", "rgba(101, 229, 221, 1)", "rgba(254, 190, 19, 1)", "rgba(11, 219, 249, 1)", "rgba(44, 161, 255, 1)"]
let testData = [
{
name: "病假",
value: "20"
},
{
name: "事假",
value: "10"
},
{
name: "婚假",
value: "5"
},
{
name: "丧假",
value: "3"
},
{
name: "年休假",
value: "7"
},
{
name: "产假",
value: "25"
},
{
name: "调休",
value: "5"
},
{
name: "陪产假",
value: "15"
}
]
// 计算插入的数据的值(根据总量调整间距大小)
let gap = (testData.reduce((a, b) => a + Number(b.value), 0) || 0) / 100; // 可以根据需要调整分母来调整间隔大小
let seriesData = [];
testData.forEach((f, fi) => {
seriesData.push({
name: f.name,
value: f.value,
itemStyle: {
color: colors[fi],
shadowColor: colors[fi],
shadowBlur: 10,
}
});
// 插入一条新的颜色透明的数据用来占位
seriesData.push({
name: "",
value: gap,
itemStyle: { color: "rgba(0, 0, 0, 0)" },
tooltip: {
show: false
}
});
});
let option = {
toolbox: {
show: true,
feature: {
saveAsImage: {},
},
},
tooltip: {},
legend: [
{
right: "10%",
top: "middle",
orient: "vertical",
icon: "circle",
itemStyle: {
color: "rgba(255, 0, 0, 0)",
borderWidth: 2,
borderColor: "auto",
},
textStyle: {
fontSize: 16,
},
itemWidth: 16,
itemHeight: 16,
itemGap: 30,
height: 200,
width: 300,
data: [
"病假",
"事假",
"婚假",
"丧假",
"年休假",
"产假",
"调休",
"陪产假",
],
},
],
series: [
{
type: "pie",
radius: ["54%", "60%"],
center: ["30%", "50%"],
itemStyle: {
borderRadius: 15,
},
label: {
show: false,
},
data: seriesData
},
{
type: "pie",
radius: ["64%", "65%"],
center: ["30%", "50%"],
itemStyle: {
color: {
type: "linear",
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{
offset: 0,
color: "rgba(44,161,255,1)",
},
{
offset: 0.8,
color: "rgba(44,161,255,0)",
},
],
},
},
silent: true,
label: {
show: false,
},
data: [0],
},
{
type: "pie",
radius: ["66.5%", "67%"],
center: ["30%", "50%"],
silent: true,
label: {
show: false,
},
data: [100],
itemStyle: {
color: {
type: "linear",
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{
offset: 0,
color: "rgba(44,161,255,0.5)",
},
{
offset: 0.8,
color: "rgba(44,161,255,0)",
},
],
},
},
},
],
};
//内容区域结束。
myChart.setOption(option);
</script>
</body>
</html>