温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么用echarts做仪表盘

发布时间:2026-09-19 10:18:26 来源:亿速云 阅读:106 作者:小樊 栏目:编程语言

下面我用**「从零到可运行」**的方式,教你用 ECharts 做仪表盘(Gauge),包含最常用场景和示例。


一、基本使用步骤

1️⃣ 引入 ECharts

<script src="https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script>

2️⃣ 准备容器

<div id="gauge" style="width: 400px;height:300px;"></div>

3️⃣ 初始化 ECharts

const chart = echarts.init(document.getElementById('gauge'));

4️⃣ 配置仪表盘(最基础示例)

const option = {
  series: [
    {
      type: 'gauge',
      min: 0,
      max: 100,
      data: [{ value: 72 }]
    }
  ]
};

chart.setOption(option);

✅ 这样你就有一个最简单的仪表盘了。


二、常见仪表盘样式配置

✅ 1. 修改起始角度 & 进度

series: [
  {
    type: 'gauge',
    startAngle: 180,
    endAngle: 0,
    min: 0,
    max: 100,
    progress: {
      show: true,
      width: 18
    },
    axisLine: {
      lineStyle: {
        width: 18
      }
    },
    data: [{ value: 65 }]
  }
]

✅ 2. 设置颜色区间(红黄绿)

axisLine: {
  lineStyle: {
    width: 18,
    color: [
      [0.3, '#ff4d4f'],
      [0.7, '#faad14'],
      [1, '#52c41a']
    ]
  }
}

✅ 3. 显示标题 & 单位

detail: {
  formatter: '{value} %',
  fontSize: 24,
  offsetCenter: [0, '70%']
},
title: {
  offsetCenter: [0, '100%'],
  fontSize: 14
},
data: [{ value: 88, name: '完成率' }]

三、动态更新仪表盘

setInterval(() => {
  const value = Math.floor(Math.random() * 100);
  chart.setOption({
    series: [{ data: [{ value }] }]
  });
}, 2000);

四、完整示例(可直接运行)

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <title>ECharts 仪表盘</title>
  <script src="https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script>
</head>
<body>
  <div id="gauge" style="width:400px;height:300px;"></div>

  <script>
    const chart = echarts.init(document.getElementById('gauge'));

    chart.setOption({
      series: [
        {
          type: 'gauge',
          min: 0,
          max: 100,
          progress: { show: true, width: 20 },
          axisLine: {
            lineStyle: {
              width: 20,
              color: [
                [0.3, '#ff4d4f'],
                [0.7, '#faad14'],
                [1, '#52c41a']
              ]
            }
          },
          pointer: { width: 5 },
          detail: {
            formatter: '{value} %',
            fontSize: 24,
            offsetCenter: [0, '70%']
          },
          data: [{ value: 80, name: 'CPU使用率' }],
          title: {
            offsetCenter: [0, '100%']
          }
        }
      ]
    });
  </script>
</body>
</html>

五、常见用途

  • CPU / 内存监控
  • 业务完成率
  • KPI 指标展示
  • 大屏可视化

如果你告诉我:

  • ✅ 用在 Vue / React?
  • ✅ 要做 多个仪表盘?
  • ✅ 要做 大屏风格?

我可以直接给你对应版本代码。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI
助
手