// 數據接入機構統計let myDom = document.getElementById('myChart');let myWidth = myDom.offsetWidth - 5; // 獲取容器寬度let myHeight = myDom.offsetHeight - 5; // 獲取容器 ...
// 數據接入機構統計
let myDom = document.getElementById('myChart');
let myWidth = myDom.offsetWidth - 5; // 獲取容器寬度
let myHeight = myDom.offsetHeight - 5; // 獲取容器高度
let myRadius = myHeight * 0.44 / 2; // 根據環形圖內圈百分比獲取內圓半徑
let myPX = (0.3 - (myRadius / myWidth)) * 100 + '%'; // 獲取白色填充圓在容器中的x軸位置百分比,以便與環形圖貼合
let myChart = echarts.init(document.getElementById('myChart'));
let option = {
title: { // 標題樣式
text: '數據接入機構統計',
textStyle: {
color: '#cccccc',
fontSize: 14
}
},
tooltip: { // 懸浮提示
trigger: 'item',
formatter: "{a} <br/>{b}: {c} ({d}%)"
},
legend: {
orient: 'vertical',
top: '20%',
right: 20, // 與容器距離調節
icon: 'circle', // 樣式調節'circle'
,'rect'
,'roundRect'
,'triangle'
,'diamond'
,'pin'
,'arrow'
,'none'等
itemWidth: 7,
textStyle: {
color: '#ffffff',
fontSize: 10,
padding: [0, 0, 0, 5] //字與圖形間的邊距
},
data:['111','222','333']
},
graphic: {
elements: [
{
type: 'group',
left: myPX, // 橫坐標位置
top: '33%', // 縱坐標位置 55% - (44% / 2)
children: [
{
type: 'circle',
shape: {
r: myRadius // 白色圓半徑
},
style: {
fill: '#fff' // 背景顏色
}
},
{
type: 'text', // 覆蓋在圓上的文字位置和樣式
style: {
text: 12345,
y: -10,
textAlign: 'center',
fontSize: 12,
fill: '#494949'
}
},
{
type: 'text',
style: {
text: '條',
y: 10,
textAlign: 'center',
fontSize: 13,
fill: '#494949'
}
}
]
}
]
},
series: [
{
name:'機構統計',
type:'pie',
radius: ['44%', '70%'], // 環形圖大小和粗細
avoidLabelOverlap: false,
center: ['30%', '55%'], // 環形圖位置
label: {
normal: {
show: false, // 設置不顯示
position: 'center' // hover時提示在圓環內
}
},
data:[
{value:335, name:'111'},
{value:310, name:'222'},
{value:234, name:'333'}
]
}
]
};
myChart.setOption(option);