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

MySQL Series 8 MySQL Server Variables

Tutorial Series MySQL series: Basic concepts of M...

Detailed tutorial on how to quickly install Zookeeper in Docker

Docker Quickly Install Zookeeper I haven't us...

Detailed explanation of MySQL 30 military rules

1. Basic Specifications (1) InnoDB storage engine...

The process of quickly converting mysql left join to inner join

During the daily optimization process, I found a ...

JavaScript implements the nine-grid mobile puzzle game

This article shares the specific code for JavaScr...

MySQL infobright installation steps

Table of contents 1. Use the "rpm -ivh insta...

Summary of MySQL common SQL statements including complex SQL queries

1. Complex SQL queries 1.1. Single table query (1...

Detailed tutorial on distributed operation of jmeter in docker environment

1. Build the basic image of jmeter The Dockerfile...

15 Linux Command Aliases That Will Save You Time

Preface In the process of managing and maintainin...

An article teaches you JS function inheritance

Table of contents 1. Introduction: 2. Prototype c...

Implementation of Webpack3+React16 code splitting

Project Background Recently, there is a project w...

About CSS floating and canceling floating

Definition of Float Sets the element out of the n...

How to display the border when td is empty

Previously, I summarized how to use CSS to achieve...