给我一个echart表格生成的 速度仪表盘
- User
给我一个echart表格生成的 速度仪表盘
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
给我一个echart表格生成的 速度仪表盘
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
下面是一个使用 ECharts 生成速度仪表盘的示例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>速度仪表盘</title>
<!-- 引入 ECharts -->
<script src="https://cdn.staticfile.org/echarts/5.4.0/echarts.min.js"></script>
</head>
<body>
<!-- 为 ECharts 准备一个定义了宽高的 DOM -->
<div id="main" style="width: 600px;height:400px;"></div>
<script type="text/javascript">
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
tooltip: {
formatter: '{a} <br/>{b} : {c}km/h'
},
series: [{
name: '速度',
type: 'gauge',
progress: {
show: true,
width: 18,
itemStyle: {
color: '#4dabf7'
}
},
axisLine: {
lineStyle: {
width: 18,
color: [
[0.4, '#4dabf7'],
[0.8, '#69db7c'],
[1, '#ff6b6b']
]
}
},
axisTick: {
distance: -25,
length: 8,
lineStyle: {
color: '#fff',
width: 2
}
},
splitLine: {
distance: -30,
length: 30,
lineStyle: {
color: '#fff',
width: 4
}
},
axisLabel: {
color: '#495057',
distance: 40,
fontSize: 16
},
anchor: {
show: true,
size: 20,
itemStyle: {
borderColor: '#4dabf7',
borderWidth: 2
}
},
title: {
show: true,
offsetCenter: [0, '70%'],
color: '#868e96',
fontSize: 20
},
detail: {
valueAnimation: true,
formatter: '{value} km/h',
color: 'auto',
fontSize: 40,
offsetCenter: [0, '40%']
},
data: [{
value: 75,
name: '当前速度'
}]
}]
};
// 使用刚指定的配置项和数据显示图表
myChart.setOption(option);
</script>
</body>
</html>
这个仪表盘包含以下特性:
你可以通过修改以下部分来自定义:
data[0].value:修改当前速度值axisLine.color:修改颜色分段值detail.formatter:修改数值显示格式axisLabel.distance:调整刻度标签位置运行效果会显示一个现代风格的仪表盘,指针会根据设置的数值自动指向对应的刻度位置,数值显示在仪表中央,并有颜色渐变效果来直观表示速度状态(蓝色表示安全,绿色表示正常,红色表示危险)。