当前位置:首页 > VUE

如何实现vue雷达图

2026-02-24 23:08:22VUE

使用 ECharts 实现 Vue 雷达图

安装 ECharts 依赖

npm install echarts --save

在 Vue 组件中引入 ECharts

import * as echarts from 'echarts'

创建雷达图容器

<template>
  <div id="radarChart" style="width: 600px; height: 400px;"></div>
</template>

初始化雷达图

mounted() {
  this.initRadarChart()
},
methods: {
  initRadarChart() {
    const chart = echarts.init(document.getElementById('radarChart'))

    const option = {
      title: {
        text: '能力雷达图'
      },
      radar: {
        indicator: [
          { name: '技术', max: 100 },
          { name: '沟通', max: 100 },
          { name: '领导力', max: 100 },
          { name: '创新', max: 100 },
          { name: '执行力', max: 100 }
        ]
      },
      series: [{
        type: 'radar',
        data: [
          {
            value: [90, 70, 80, 85, 75],
            name: '能力评估'
          }
        ]
      }]
    }

    chart.setOption(option)
  }
}

使用 Vue-ECharts 封装组件

安装 vue-echarts

npm install echarts vue-echarts

创建可复用的雷达图组件

<template>
  <v-chart :option="option" autoresize />
</template>

<script>
import { use } from 'echarts/core'
import { RadarChart } from 'echarts/charts'
import {
  TitleComponent,
  TooltipComponent,
  LegendComponent,
  RadarComponent
} from 'echarts/components'
import { CanvasRenderer } from 'echarts/renderers'
import VChart from 'vue-echarts'

use([
  RadarChart,
  TitleComponent,
  TooltipComponent,
  LegendComponent,
  RadarComponent,
  CanvasRenderer
])

export default {
  components: { VChart },
  props: {
    indicators: Array,
    seriesData: Array
  },
  computed: {
    option() {
      return {
        title: { text: '技能评估' },
        tooltip: {},
        legend: { data: ['当前能力'] },
        radar: { indicator: this.indicators },
        series: [{
          name: '能力',
          type: 'radar',
          data: this.seriesData
        }]
      }
    }
  }
}
</script>

自定义雷达图样式

修改雷达图外观

option: {
  radar: {
    shape: 'circle',
    splitNumber: 5,
    radius: '70%',
    axisName: {
      color: '#333',
      fontSize: 14
    },
    splitArea: {
      areaStyle: {
        color: ['rgba(114, 172, 209, 0.2)']
      }
    },
    axisLine: {
      lineStyle: {
        color: 'rgba(114, 172, 209, 0.8)'
      }
    }
  },
  series: [{
    itemStyle: {
      color: '#4bacc6'
    },
    lineStyle: {
      width: 2,
      color: '#4bacc6'
    },
    areaStyle: {
      color: 'rgba(75, 172, 198, 0.4)'
    }
  }]
}

响应式雷达图实现

添加窗口大小变化监听

mounted() {
  this.initRadarChart()
  window.addEventListener('resize', this.handleResize)
},
beforeDestroy() {
  window.removeEventListener('resize', this.handleResize)
},
methods: {
  handleResize() {
    this.chart.resize()
  }
}

使用 computed 属性动态生成数据

如何实现vue雷达图

computed: {
  radarData() {
    return this.$store.getters.skillData.map(item => {
      return {
        name: item.skillName,
        max: 100,
        color: this.getColor(item.level)
      }
    })
  }
}

标签: 如何实现vue
分享给朋友:

相关文章

vue设计与实现下载

vue设计与实现下载

vue设计与实现电子书下载 《Vue.js设计与实现》是一本深入解析Vue.js框架原理的书籍,由霍春阳(HcySunYang)撰写。以下是获取该资源的常见途径: 正版购买渠道 京东、当当、天猫等…

vue实现vnc

vue实现vnc

Vue 实现 VNC 客户端 在 Vue 项目中实现 VNC 客户端功能,可以通过集成现有的 VNC 客户端库或组件完成。以下是具体实现方法: 安装依赖库 使用 noVNC 或其他 VNC 客户端…

vue实现mouseout

vue实现mouseout

Vue 实现 mouseout 事件的方法 在 Vue 中实现 mouseout 事件可以通过多种方式完成,以下是几种常见的方法: 使用 v-on 指令 Vue 提供了 v-on 指令(或简写为 @…

vue 实现excel

vue 实现excel

Vue 实现 Excel 功能 前端导出 Excel 使用 xlsx 库可以轻松实现前端 Excel 导出功能。安装依赖: npm install xlsx 导出 Excel 示例代码: impo…

vue实现标注

vue实现标注

Vue 实现标注功能的方法 使用 Vue 实现标注功能可以通过多种方式实现,以下介绍几种常见的方法: 1. 使用 HTML5 Canvas 实现标注 Canvas 提供了强大的绘图能力,适合实现复…

vue博客实现

vue博客实现

Vue 博客实现步骤 项目初始化与基础配置 使用 Vue CLI 或 Vite 创建项目,安装基础依赖如 vue-router 和状态管理库(如 pinia)。配置路由文件实现页面跳转逻辑,例如博客首…