Sample code for implementing radar chart with vue+antv

Sample code for implementing radar chart with vue+antv

1. Download Dependency

npm install @antv/data-set

npm install @antv/g2

2. Code Implementation

<template>
  <div ref="container" />
</template>
 
<script>
import DataSet from '@antv/data-set'
import { Chart } from '@antv/g2'
export default {
// Create a radar chart mounted() {
    this.constradar()
  },
  methods: {
    constradar() {
      const data = [
        { item: 'Work efficiency', a: 70, b: 30 },
        { item: 'Attendance', a: 60, b: 70 },
        { item: 'Positiveness', a: 50, b: 60 },
        { item: 'Helping a colleague', a: 40, b: 50 },
        { item: 'Self-directed learning', a: 60, b: 70 },
        { item: 'Accuracy', a: 70, b: 50 }
      ]
      const { DataView } = DataSet
      const dv = new DataView().source(data)
      dv.transform({
        type: 'fold',
        fields: ['a', 'b'], // Expand field set key: 'user', // key field value: 'score' // value field })
 
      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()
 
//Modify data const newData = [
        { item: 'Work efficiency', a: 20, b: 30 },
        { item: 'Attendance', a: 30, b: 70 },
        { item: 'Positiveness', a: 10, b: 60 },
        { item: 'Helping a colleague', a: 40, b: 50 },
        { item: 'Self-directed learning', a: 60, b: 70 },
        { item: 'Accuracy', a: 20, b: 50 }
      ]
      // Update immediately setTimeout(() => {
        // Start processing data const dv = new DataView().source(newData)
        dv.transform({
          type: 'fold',
          fields: ['a', 'b'], // Expand field set key: 'user', // key field value: 'score' // value field })
        // Processing is finished // Use the processed data to update the icon chart.changeData(dv.rows)
      }, 3000)
    }
  }
}
</script>
 
<style></style>

3. Achievement Effect

Before data modification

After data modification

This is the end of this article about vue+antv implementing radar chart. For more related vue radar chart content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Example steps for using AntV X6 with Vue.js
  • VUE and Antv G6 realize online topology map editing operation
  • Reference Antv G2 in the vue project, taking the pie chart as an example
  • Sample code for using antv in Vue

<<:  Summary of Button's four Click response methods

>>:  Example code for implementing a text marquee with CSS3

Recommend

Graphical tutorial on installing CentOS 7.3 on VMWare

Illustrated CentOS 7.3 installation steps for you...

Detailed explanation of the adaptive adaptation problem of Vue mobile terminal

1. Create a project with vue ui 2. Select basic c...

JS asynchronous execution principle and callback details

1. JS asynchronous execution principle We know th...

CSS draw a lollipop example code

Background: Make a little progress every day, acc...

Pure CSS to achieve left and right drag to change the layout size

Utilize the browser's non- overflow:auto elem...

js to implement a simple bullet screen system

This article shares the specific code of native j...

How to use resize to implement image switching preview function

Key Points The CSS resize property allows you to ...

Analysis of the principles of Mysql dirty page flush and shrinking table space

mysql dirty pages Due to the WAL mechanism, when ...

Linux CentOS MySQL database installation and configuration tutorial

Notes on installing MySQL database, share with ev...

How to configure Nginx to support ipv6 under Linux system

1. Check whether the existing nginx supports ipv6...

Detailed steps for Spring Boot packaging and uploading to Docker repository

Important note: Before studying this article, you...

Detailed process of configuring Https certificate under Nginx

1. The difference between Http and Https HTTP: It...