Home Web Front-end Vue.js Report import and data correlation skills for Vue statistical charts

Report import and data correlation skills for Vue statistical charts

Aug 18, 2023 pm 02:55 PM
vue Skill statistic chart Data association Report import

Report import and data correlation skills for Vue statistical charts

Report import and data correlation skills for Vue statistical charts

Introduction: Vue, as a popular front-end framework, is widely used in various Web applications. In web applications, statistical charts are one of the most common ways to display data. This article will introduce how to import the statistical chart library in Vue, and show how to achieve dynamic updating of charts through data association techniques.

1. Selection and import of report libraries
In Vue, there are many excellent statistical chart libraries to choose from, such as ECharts, HighCharts, etc. When choosing, you can evaluate the project needs and choose the most suitable library.

1.1 Import of ECharts
ECharts is a very powerful open source data visualization library. Using ECharts in the Vue project can display various statistical charts. First, install ECharts in the Vue project:

1

npm install echarts --save

Copy after login

Then import the echarts library in the Vue component:

1

import echarts from 'echarts'

Copy after login

1.2 Import of HighCharts
HighCharts is another commonly used data visualization library with Rich chart types and flexible configuration options. To use HighCharts in the Vue project, first install HighCharts:

1

npm install highcharts --save

Copy after login

Next, import the corresponding module in the Vue component:

1

2

import HighCharts from 'highcharts'

import HighChartsVue from 'highcharts-vue'

Copy after login

2. Data association and chart update
In the Vue project In , it is a very common practice to implement dynamic updating of charts through data association techniques. The following will be explained in detail with examples.

2.1 ECharts data association and chart update

First, define the data attributes in the Vue component

1

2

3

4

5

6

7

8

data() {

  return {

    chartData: {

      xData: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],

      yData: [120, 200, 150, 80, 70, 110]

    }

  }

},

Copy after login

Then, in the mounted hook of the Vue life cycle Draw the chart

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

mounted() {

  this.initChart()

},

 

methods: {

  initChart() {

    let myChart = echarts.init(this.$refs.chart)

    let option = {

      xAxis: {

        type: 'category',

        data: this.chartData.xData

      },

      yAxis: {

        type: 'value'

      },

      series: [{

        data: this.chartData.yData,

        type: 'bar'

      }]

    }

    myChart.setOption(option)

  }

}

Copy after login

Finally, dynamically update the chart by changing the data in chartData

1

this.chartData.yData = [150, 120, 180, 90, 100, 130]

Copy after login

2.2 HighCharts data association and chart update

First, define the data properties in the Vue component

1

2

3

4

5

6

7

8

9

10

11

data() {

  return {

    chartData: {

      categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],

      series: [{

        name: 'Sales',

        data: [120, 200, 150, 80, 70, 110]

      }]

    }

  }

},

Copy after login

Then, draw the chart in the mounted hook of the Vue life cycle

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

mounted() {

  this.initChart()

},

 

methods: {

  initChart() {

    HighCharts.chart(this.$refs.chart, {

      xAxis: {

        categories: this.chartData.categories

      },

      yAxis: {

        title: {

          text: 'Amount'

        }

      },

      series: this.chartData.series

    })

  }

}

Copy after login

Finally, by changing chartDataData in to achieve dynamic updating of charts

1

this.chartData.series[0].data = [150, 120, 180, 90, 100, 130]

Copy after login

Summary:
Through the introduction of this article, we can understand how to import the statistical chart library in Vue, and show how to achieve it through data association techniques Dynamic updates of charts. I hope this article will be helpful to readers who are using Vue to develop statistical chart functions.

Note: The above examples are only demonstration codes, and the specific usage needs to be adjusted according to the actual needs of the project.

The above is the detailed content of Report import and data correlation skills for Vue statistical charts. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use echarts in vue How to use echarts in vue May 09, 2024 pm 04:24 PM

How to use echarts in vue

The role of export default in vue The role of export default in vue May 09, 2024 pm 06:48 PM

The role of export default in vue

How to use map function in vue How to use map function in vue May 09, 2024 pm 06:54 PM

How to use map function in vue

The difference between event and $event in vue The difference between event and $event in vue May 08, 2024 pm 04:42 PM

The difference between event and $event in vue

The role of onmounted in vue The role of onmounted in vue May 09, 2024 pm 02:51 PM

The role of onmounted in vue

The difference between export and export default in vue The difference between export and export default in vue May 08, 2024 pm 05:27 PM

The difference between export and export default in vue

Onmounted in vue corresponds to which life cycle of react Onmounted in vue corresponds to which life cycle of react May 09, 2024 pm 01:42 PM

Onmounted in vue corresponds to which life cycle of react

What are hooks in vue What are hooks in vue May 09, 2024 pm 06:33 PM

What are hooks in vue

See all articles