Echarts用极坐标实现【圆形的仪表盘】

第一次尝试使用Echarts极坐标实现图表,记录一下。

实现echarts版本:4.9.0

先上效果图如下:

option参数如下(没有title):

polarOption = {
  color: chartColor,
  angleAxis: [
    {
      polarIndex: 0,
      startAngle: 180,
      max: 10,
      min: 0,
      interval: 2.5,
      splitNumber: 4,
      zlevel: 22,
      axisLabel: {
        show: true,
        margin: 1,
        color: '#BBBBC4',
      },
      axisTick: {
        inside: true,
        length: 5,
        lineStyle: {
          color: '#fff',
        },
      },
      axisLine: {
        show: false,
      },
      splitLine: {
        show: false,
      },
    },
    {
      polarIndex: 1,
      startAngle: 180,
      max: 10,
      min: 0,
      interval: 0.5,
      zlevel: 20,
      splitNumber: 4,
      axisLabel: {
        show: false,
      },
      axisLine: {
        show: false,
      },
      splitLine: {
        show: false,
      },
      axisTick: {
        inside: true,
        show: true,
        length: 2,
        lineStyle: {
          color: '#fff',
        },
      },
    },
  ],
  polar: [
    {
      radius: ['55%', '70%'],
      center: ['49%', '57%'],
    },
    {
      radius: ['55%', '70%'],
      center: ['49%', '57%'],
    },
  ],
  radiusAxis: [
    {
      polarIndex: 0,
      type: 'category',
      data: ['Thu'],
      z: 10,
      axisLine: {
        show: false,
      },
      axisLabel: {
        show: false,
      },
      splitLine: {
        show: false,
      },
      axisTick: {
        show: false,
      },
      boundaryGap: false,
    },
    {
      polarIndex: 1,
      z: 15,
      axisLine: {
        show: false,
      },
      axisLabel: {
        show: false,
      },
      splitLine: {
        show: false,
      },
      axisTick: {
        show: false,
      },
    },
  ],
  series: [
    {
      type: 'bar',
      polarIndex: 0,
      showBackground: true,
      backgroundStyle: {
        color: '#E1E4EB',
      },
      data: [7.8],
      coordinateSystem: 'polar',
      name: 'Thu',
      stack: 'a',
      barWidth: 20,
      emphasis: {
        focus: 'series',
      },
    },
  ],
}

灵感来源于官方的极坐标柱状图例子Examples - Apache ECharts

angleAxis角度轴设置

设置两个角度坐标轴,一个对应外层大刻度,一个对应里层小刻度(如果不需要两个大小的刻度可以只设置一个坐标轴)

// 外层大刻度
axisTick: {
    inside: true,
    length: 5,
    lineStyle: {
    color: '#000',
    },
  }      
// 里层小刻度
  axisTick: {
    inside: true,
    show: true,
    length: 2,
    lineStyle: {
      color: '#000',
    },
  },
radiusAxis径向轴设置

因为设置了两个角度轴,所以对应要设置两个径向轴,参数可调整

polar极坐标系设置

设置极坐标系的center(中心)、radius(半径大小)

polar: [
    {
      radius: ['55%', '70%'],
      center: ['49%', '57%'],
    },
    {
      radius: ['55%', '70%'],
      center: ['49%', '57%'],
    },
  ]
series图表配置

这里用的是第一个坐标系,所以标记了index

polarIndex: 0,

  series: [
    {
      type: 'bar',
      polarIndex: 0,
      showBackground: true,
      backgroundStyle: {
        color: '#E1E4EB',
      },
      data: [7.8],
      coordinateSystem: 'polar',
      name: 'Thu',
      stack: 'a',
      barWidth: 20,
      emphasis: {
        focus: 'series',
      },
    },
  ],

到这就完成啦,其中还有一些level的小细节,不过对这个图表影响不大。

  • 7
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值