【echarts】15、echarts+vue2 -雷达图

前言

基于echarts5.x和vue2实现
记录以便日后查阅

实现效果

在这里插入图片描述

代码实现

<template>
  <div class="chart-wrap">
    <div id="chart12" class="chart" />
  </div>
</template>

<script>
export default {
  name: 'Index',
  data () {
    return {
      chart: null,
      data1: [60, 70, 50, 80, 66, 77],
      data2: [86, 83, 82, 91, 90, 87]
    }
  },
  mounted() {
    this.createChartHandler()
  },
  methods: {
    // 创建图表
    createChartHandler () {
      this.chart = this.$echarts.init(document.getElementById('chart12'))
      this.chart.setOption(this.getChartOption(this.data1, this.data2))
      window.addEventListener('resize', () => {
        setTimeout(() => {
          this.chart.resize()
        })
      })
    },
    // 获取图表配置项
    getChartOption (data1, data2) {
      return {
        normal: {
          top: 0,
          left: 0,
          width: 0,
          height: 0,
          zIndex: 6,
          backgroundColor: ''
        },
        legend: {
          show: false,
          data: [
            {
              name: '上月指数',
              icon: 'circle'
            },
            {
              name: '当月指数',
              icon: 'circle'
            }
          ],
          left: 'center',
          position: ['bottom', 'center']
        },
        color: ['rgba(245, 166, 35, 1)', 'rgba(19, 173, 255, 1)'],
        radar: {
          center: ['50%', '50%'],
          axisName: {
            // (圆外的标签)雷达图每个指示器名称的配置项。
            fontSize: 12,
            color: 'rgba(221,221,221,0.79)',
            formatter: function (value, indicator) {
              if (value !== '安防态势' && value !== '产业经济') {
                const charArr = value.split('')
                return charArr[0] + charArr[1] + '\n' + charArr[2] + charArr[3]
              }
              return value
            }
          },
          axisNameGap: 4,
          radius: ['0%', '70%'],
          splitNumber: 6,
          splitArea: {
            areaStyle: {
              color: ['transparent']
            }
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: 'rgba(221,221,221,0.79)' //
            }
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: 'rgba(221,221,221,0.79)' //
            }
          },
          indicator: [
            {
              text: '安防态势',
              max: 100
            },
            {
              text: '消防状态',
              max: 100
            },
            {
              text: '能耗监测',
              max: 100
            },
            {
              text: '产业经济',
              max: 100
            },
            {
              text: '设备运行',
              max: 100
            },
            {
              text: '环境监测',
              max: 100
            }
          ]
        },
        series: [
          {
            name: '上月指数',
            type: 'radar',
            symbol: 'circle',
            symbolSize: 4,
            areaStyle: {
              color: '#06C88C'
            },
            itemStyle: {
              color: '#06C88C'
            },
            lineStyle: {
              type: 'dashed',
              color: '#06C88C',
              width: 2
            },
            data: [data1]
          },
          {
            name: '当月指数',
            type: 'radar',
            symbol: 'circle',
            symbolSize: 4,
            itemStyle: {
              color: '#63BCFF'
            },
            areaStyle: {
              color: '#63BCFF'
            },
            lineStyle: {
              color: '#63BCFF',
              width: 2,
              type: 'dashed'
            },
            data: [data2]
          }
        ]
      }
    }
  }
}
</script>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值