用echarts 仪表盘修改开发的环形图
效果图
核心代码
import * as echarts from 'echarts';
var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom);
var option;
option = {
series: [
{
type: 'gauge',
center: ['50%', '50%'],
startAngle: 90,
endAngle: -270,
min: 0,
max: 100,
splitNumber: 0,
itemStyle: {
color: '#5cc949'
},
progress: {
show: true,
width: 10
},
pointer: {
show: false
},
axisLine: {
// 设置背景色和宽度
lineStyle: {
width: 10,
color: [[1, '#e3e3e3']]
}
},
splitLine: {
show: false
},
axisLabel: {
show: false
},
detail: {
valueAnimation: true,
width: '60%',
offsetCenter: [0, '0'],
fontSize: 60,
formatter: '{value} %',
color: 'auto'
},
data: [
{
valueStarting: 20
}
]
}
]
};
setInterval(function () {
const random = +(Math.random() * 60).toFixed(2);
myChart.setOption({
series: [
{
data: [
{
value: random
}
]
}
]
});
}, 2000);
option && myChart.setOption(option);