iis服务器助手广告广告
返回顶部
首页 > 资讯 > 前端开发 > JavaScript >vue+antv实现雷达图的示例代码
  • 403
分享到

vue+antv实现雷达图的示例代码

2024-04-02 19:04:59 403人浏览 安东尼
摘要

一、下载依赖 npm install @antv/data-set npm install @antv/g2 二、代码实现 <template> <di

一、下载依赖

npm install @antv/data-set

npm install @antv/g2

二、代码实现


<template>
  <div ref="container" />
</template>
 
<script>
import DataSet from '@antv/data-set'
import { Chart } from '@antv/g2'
export default {
// 创建雷达图
  mounted() {
    this.constradar()
  },
  methods: {
    constradar() {
      const data = [
        { item: '工作效率', a: 70, b: 30 },
        { item: '考勤', a: 60, b: 70 },
        { item: '积极性', a: 50, b: 60 },
        { item: '帮助同事', a: 40, b: 50 },
        { item: '自主学习', a: 60, b: 70 },
        { item: '正确率', a: 70, b: 50 }
      ]
      const { DataView } = DataSet
      const dv = new DataView().source(data)
      dv.transfORM({
        type: 'fold',
        fields: ['a', 'b'], // 展开字段集
        key: 'user', // key字段
        value: 'score' // value字段
      })
 
      const chart = new Chart({
        container: this.$refs.container,
        autoFit: true,
        height: 500
      })
      chart.data(dv.rows)
      chart.scale('score', {
        min: 0,
        max: 80
      })
      chart.coordinate('polar', {
        radius: 0.8
      })
      chart.tooltip({
        shared: true,
        showCrosshairs: true,
        crosshairs: {
          line: {
            style: {
              lineDash: [4, 4],
              stroke: '#333'
            }
          }
        }
      })
      chart.axis('item', {
        line: null,
        tickLine: null,
        grid: {
          line: {
            style: {
              lineDash: null
            }
          }
        }
      })
      chart.axis('score', {
        line: null,
        tickLine: null,
        grid: {
          line: {
            type: 'line',
            style: {
              lineDash: null
            }
          }
        }
      })
 
      chart.line().position('item*score').color('user').size(2)
      chart
        .point()
        .position('item*score')
        .color('user')
        .shape('circle')
        .size(4)
        .style({
          stroke: '#fff',
          lineWidth: 1,
          fillOpacity: 1
        })
      chart.area().position('item*score').color('user')
      chart.render()
 
//修改数据
      const newData = [
        { item: '工作效率', a: 20, b: 30 },
        { item: '考勤', a: 30, b: 70 },
        { item: '积极性', a: 10, b: 60 },
        { item: '帮助同事', a: 40, b: 50 },
        { item: '自主学习', a: 60, b: 70 },
        { item: '正确率', a: 20, b: 50 }
      ]
      // 立刻更新
      setTimeout(() => {
        // 处理数据开始
        const dv = new DataView().source(newData)
        dv.transform({
          type: 'fold',
          fields: ['a', 'b'], // 展开字段集
          key: 'user', // key字段
          value: 'score' // value字段
        })
        // 处理结束
 
        // 正式使用处理之后的数据进行图标更新
        chart.changeData(dv.rows)
      }, 3000)
    }
  }
}
</script>
 
<style></style>

三、实现效果

数据修改前

  

数据修改后

 

到此这篇关于Vue+antv实现雷达图的文章就介绍到这了,更多相关vue雷达图内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: vue+antv实现雷达图的示例代码

本文链接: https://www.lsjlt.com/news/159273.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作