• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

日常记录 创建自定义样式的 echarts 仪表盘

武飞扬头像
墨小谖
帮助1

Echarts 仪表盘

需要自定义样式和指针,实现了渐变的表盘和数据展示,代码记录一下~
注: 指针这里不知道怎么画,所以把图片转成base64直接使用了,大佬们如果有啥更好的方法欢迎指导~

import * as echarts from 'echarts';

var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom, 'dark');
var option;

const baseIcon = 'image://data:image/png;base64,...'; // 太长了 这里省略了

option = {
  tooltip: {
    formatter: '{a} <br/>{b} : {c}%'
  },
  series: [
    {
      name: 'Pressure',
      type: 'gauge',
      detail: {
        formatter: '{value}%',
        color: 'rgba(	238,130,238, 1)',
        fontWeight: 700,
        fontSize: 100,
        fontFamily: 'Arial',
        offsetCenter: ['0', '-24%']
      },
      data: [
        {
          value: 50,
          name: 'SCORE'
        }
      ],
      endAngle: 0,
      colorBy: 'data',
      center: ['50%', '95%'],
      startAngle: 180,
      min: 0,
      splitNumber: 10,
      axisLine: {
        show: true,
        roundCap: true,
        lineStyle: {
          color: [
            [
              1,
              new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                {
                  offset: 0,
                  color: 'rgba(123,104,238,0.85)'
                },
                {
                  offset: 0.5,
                  color: 'rgba(221,160,221,0.85)'
                },
                {
                  offset: 1,
                  color: 'rgba(255,182,193,0.85)'
                }
              ])
            ]
          ],
          width: 16
        }
      },
      splitLine: {
        length: '6%',
        distance: 7,
        lineStyle: {
          color: '#ffffff',
          width: 1
        }
      },
      // 刻度样式
      axisTick: {
        show: true,
        splitNumber: 5,
        lineStyle: {
          color: '#ffffff'
        }
      },
      // 刻度标签
      axisLabel: {
        distance: 25,
        formatter: function (value) {
          if (value % 20 === 0) return value   '%';
        },
        color: '#ffffff',
        fontFamily: 'Arial',
        fontSize: 20
      },
      // 指针
      pointer: {
        icon: baseIcon,
        length: 25,
        width: 16,
        offsetCenter: [0, '-94%']
      },
      title: {
        offsetCenter: ['0', '0%'],
        color: 'rgba(255, 255, 255, 1)',
        fontWeight: 400
      }
    }
  ]
};

option && myChart.setOption(option);

学新通

效果展示

最终效果如图
学新通
echarts 文档很详细 基本就照着文档属性一个一个配的没啥大问题~

参考文档: https://echarts.apache.org/examples/zh/index.html#chart-type-gauge

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgbhiab
系列文章
更多 icon
同类精品
更多 icon
继续加载