自定义仪表盘
样式如下
代码如下
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 引入 ECharts 文件 -->
<script src="echarts.min.js"></script>
<title>Document</title>
</head>
<body>
<!-- 为 ECharts 准备一个具备大小(宽高)的 DOM -->
<div id="main" style="width: 600px;height:400px;"></div>
<img src="e7a7ddebae2a69f5f92a4ad8648d7ba.png" id="bg_img" style="display:none" />
<script type="text/javascript">
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
tooltip: {
formatter: '{a} <br/>{b} : {c}M/S'
},
// toolbox: {//重置,保存图片
// feature: {
// restore: {},
// saveAsImage: {}
// }
// },
series: [
{
name: '业务指标',
type: 'gauge',
// center: ["50%", "45%"], // 仪表位置
// radius: "80%", //仪表大小
radius: 110, //半径
startAngle: 240,//起始角度。圆心 正右手侧为0度,正上方为90度,正左手侧为180度。
endAngle: -60, //结束角度。
min: 0,
max: 20,
//仪表盘轴线相关配置。
axisLine: {
show: true,//将图表轴线、label、分割线、隐藏,只保留刻度
lineStyle: {
color: [
[1, '#2bbcd9']
],
width: 5,//表盘宽度
opacity: 1
}
},
splitLine: {
show: false
},
axisTick: {
show: false
},
axisLabel: {
show: false
},
pointer: { //指针样式
length: '45%'
},
detail: {
show: false
}
},
{
name: '业务指标',
type: 'gauge',
// center: ["50%", "45%"], // 仪表位置
// radius: "80%", //仪表大小
radius: 30, //半径
startAngle: 300,//起始角度。圆心 正右手侧为0度,正上方为90度,正左手侧为180度。
endAngle: -59.9, //结束角度。
min: 0,
max: 20,
axisLine: {
show: true,//将图表轴线、label、分割线、隐藏,只保留刻度
lineStyle: {
color: [
[1, '#2bbcd9']
],
width: 1,//表盘宽度
opacity: 1
}
},
splitLine: {
show: false
},
axisTick: {
show: false
},
axisLabel: {
show: false
},
pointer: { //指针样式
length: '45%'
},
detail: {
show: false
}
},
{
name: '业务指标',
type: 'gauge',
// center: ["50%", "45%"], // 仪表位置
// radius: "80%", //仪表大小
radius: 100, //半径
startAngle: 240,//起始角度。圆心 正右手侧为0度,正上方为90度,正左手侧为180度。
endAngle: -60, //结束角度。
min: 0,
max: 20,
detail: { //仪表盘详情,用于显示数据。
formatter: '{value}M/S',
offsetCenter: [0, 95], // x, y,单位px
textStyle: {
color: '#2bbbd6',
fontSize: 16
}
},
axisLabel: {//刻度标签。
show: true,
color: "#2abbda",
fontSize: 12,
distance: 10,//位置 负数会显示在外层
formatter: function (v) {
return v;
},
},
axisTick: { //刻度样式
length: 5,//刻度长度
splitNumber: 2,// 增加刻度密度
lineStyle: {
color: "#fff",
// color: {
// image: document.getElementById('bg_img'),//刻度背景
// repeat: 'no-repeat'
// },
width: 1
},
},
splitLine: {//分隔线样式
show: true,
length: 15,
lineStyle: {
color: "#fff",
width: 2
},
},
axisLine: { //仪表盘轴线相关配置。
show: true,//将图表轴线、label、分割线、隐藏,只保留刻度
lineStyle: {
color: [
[1, new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
offset: 0,
color: '#2cbbd9'
}, {
offset: 0.5,
color: '#37d3a4'
}, {
offset: 1,
color: '#71d07f'
}
])]
],
width: 20,//表盘宽度
opacity: 1
}
},
data: [{ value: 10 }]
},
]
};
// setInterval(function () {
option.series[2].data[0].value = (Math.random() * 10).toFixed(2) - 0;
myChart.setOption(option, true);
// }, 2000);
</script>
</body>
</html>
详细参数说明: https://www.w3cschool.cn/echarts_tutorial/