代码:
<html>
<head>
<title>图表绘制</title>
<style type="text/css">
#dashboard {
width: 402px;
height: 293px;
margin: 50px auto;
}
</style>
</head>
<body>
<!-- 为ECharts准备一个具备大小(宽高)的Dom -->
<div id="dashboard"></div>
<script src="https://cdn.bootcdn.net/ajax/libs/echarts/5.0.1/echarts.js"></script>
<!-- <script src="https://cdn.bootcdn.net/ajax/libs/echarts/4.8.0/echarts-en.common.js"></script> -->
<script type="text/javascript">
const numericalData = [-3, -2.15, -1.29, -0.5, 0.3, 1.28, 2.14, 3]
const standard = ['1', '2', '3', '4', '5', '6', '7']
const realData = 0.7
const fakeData = 0.1
const colorTemplate1 = [
[0.142, '#83c970'],[0.284, '#c93600'],[0.426, '#0a5dc9'],
[0.568, '#c3c900'],[0.710, '#c900ab'],[0.852, '#0cc902'],[1, '#340ec9']
]
var myChart3 = echarts.init(document.getElementById('dashboard'));
var option3 = {
series: [
{
z: 0,
type: 'pie',
radius: '80%',
startAngle: 0,
hoverAnimation: false,
clockWise: false,
itemStyle: {
normal: {
color: new echarts.graphic.RadialGradient(0.5, 1, 1, [
{
offset: 0.5,
color: 'rgba(255,255,255,1)',
}, {
offset: 1,
color: 'rgba(33,150,243,0.01)'
}])
}
},
label: {
show: false
},
data: [{
value: 0.5
}, {
value: 0.5,
itemStyle: {
color: 'rgba(0,0,0,0)'
}
}]
},
{
type: 'gauge',
radius: '80%',
min: -3,
max: 3,
startAngle: 180,
endAngle: 0,
splitNumber: 6,
axisLine: {
roundCap: true,
lineStyle: {
width: 6,
color: colorTemplate1
}
},
splitLine:{show:false},
axisTick: {show: false},
pointer: {
icon: 'path://M2.9,0.7L2.9,0.7c1.4,0,2.6,1.2,2.6,2.6v115c0,1.4-1.2,2.6-2.6,2.6l0,0c-1.4,0-2.6-1.2-2.6-2.6V3.3C0.3,1.9,1.4,0.7,2.9,0.7z',
width: 3,
length: '80%',
offsetCenter: [0, '-10%'],
itemStyle: {
color: '#000'
}
},
anchor: {
show: true,
showAbove: true,
size: 6,
itemStyle: {
borderWidth: 2,
borderColor: '#000'
}
},
axisLabel: {
show: false,
distance: -20,
color: '#666',
fontSize: 12,
formatter: (val) => {
val = Number(val)
for (let i = 0; i < numericalData.length; i++) {
if (val > numericalData[i] && val <= numericalData[i + 1]) {
return standard[i]
}
if (val === numericalData[0]) {
return standard[0]
}
}
}
},
detail: {
fontSize: 14,
offsetCenter: [0, '30%'],
valueAnimation: true,
formatter: function (value) {
return "标题:"+ Math.round(value * 100) + '%';
},
color: '#333'
},
data: [{
value: 0.70
}]
},{
type: 'gauge',
radius: '98%',
min: -3,
max: 3,
detail: {show: false},
startAngle: 170,
endAngle: 10,
splitNumber: 6,
data: [fakeData],
axisLine: {
show: false
},
splitLine:{
show:false
},
axisTick: {show: false},
axisLabel: {
show: true,
distance: -20,
color: '#666',
fontSize: 12,
formatter: (val) => {
val = Number(val)
for (let i = 0; i < numericalData.length; i++) {
if (val > numericalData[i] && val <= numericalData[i + 1]) {
return standard[i]
}
if (val === numericalData[0]) {
return standard[0]
}
}
}
},
pointer: {show: false}
}]
};
myChart3.setOption(option3);
</script>
</body>
</html>

- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
效果图:
