给我一个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.
Below is an example of how to create a simple speedometer gauge chart using ECharts. This example assumes you have a basic understanding of HTML and JavaScript. If you're integrating this into a more complex project, ensure you've included the ECharts library properly. For standalone testing, I'll provide a complete HTML snippet that includes the ECharts library.
First, ensure you have the ECharts library included in your project. For this example, we'll use a CDN link for simplicity.
Create an HTML file (e.g., speedometer.html) and add the following code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Speedometer Gauge with ECharts</title>
<script src="https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script>
</head>
<body>
<div id="speedometer" style="width: 400px; height: 400px;"></div>
<script src="script.js"></script>
</body>
</html>
Create a JavaScript file (e.g., script.js) in the same directory as your HTML file and add the following code:
// Get the element
var speedometerChart = document.getElementById('speedometer');
// Based on prepared DOM, initialize echarts instance
var myChart = echarts.init(speedometerChart);
// Specify the configuration items and data for the chart
var option = {
series: [
{
type: 'gauge',
axisLine: { // 坐标轴线
lineStyle: { // 属性lineStyle控制线条样式
color: [[0.09, 'lime'], [0.82, '#1e90ff'], [1, '#ff4500']],
width: 3,
shadowColor: '#fff', // 默认透明
shadowBlur: 10
}
},
axisTick: { // 坐标轴小标记
splitNumber: 10, // 坐标轴的分割段数
length: 12, // 属性length控制线长
lineStyle: { // 属性lineStyle控制线条样式
color: 'auto'
}
},
axisLabel: { // 坐标轴文本标签,详见axis.axisLabel
textStyle: { // 其余属性默认使用全局文本样式,详见TEXTSTYLE
fontSize: 12,
color: 'auto'
}
},
splitLine: { // 分隔线
length: 20, // 属性length控制线长
lineStyle: { // 属性lineStyle(详见lineStyle)控制线条样式
color: 'auto'
}
},
title: { // 其余属性默认使用全局文本样式,详见TEXTSTYLE
textStyle: { // 文本样式
fontSize: 14
},
offsetCenter: [0, '-30%'], // x, y,单位px
},
detail: {
formatter: '{value} km/h',
textStyle: { // 其余属性默认使用全局文本样式,详见TEXTSTYLE
fontSize: 24
},
offsetCenter: [0, '0%'], // x, y,单位px
},
data: [{value: 50, name: 'Speed'}],
pointer: {
icon: 'path://M2.9,0.7L2.9,0.7c1.4,1.4,3.6,1.8,5.6,1.2c2.1-0.7,3.5-2.5,3.3-4.8c-0.2-2.3-2.4-4-4.8-3.3L2.9,0.7z',
width: 6,
length: '80%',
itemStyle: {
normal: {
color: 'auto'
}
}
},
radius: '90%',
startAngle: 200,
endAngle: -20,
// 坐标轴的小标记,详见axis.axisTick
min: 0,
max: 120, // 速度范围
}
]
};
// Use the configuration items and data just specified to show the chart.
myChart.setOption(option);
// Dynamically update the chart
setInterval(function () {
// Generate a random speed between 0 and 120
var value = Math.round(Math.random() * 100) % 121;
myChart.setOption({
series: [{
data: [{value: value, name: 'Speed'}]
}]
});
}, 2000); // Update every 2000 milliseconds (2 seconds)
<head> of the HTML.<div> with the id speedometer is created to hold the chart.speedometer div.option object), specifying it as a gauge chart with customized visual elements (colors, sizes, etc.).setInterval to dynamically update the chart's value every 2 seconds, simulating a speedometer reading.speedometer.html file in a web browser.