Vue imports Echarts to realize line scatter chart

Vue imports Echarts to realize line scatter chart

This article shares the specific code of Vue importing Echarts to realize the line scatter chart for your reference. The specific content is as follows

Effect picture:

1. Import echarts in vue-cli

Download it to the project through the command: npm install echarts --save, then import it in the main.js of the project and save it on the prototype of vue.
The main.js code is as follows:

import Vue from 'vue'
import App from './App.vue'
const echarts = require("echarts")
Vue.prototype.$echarts = echarts
Vue.config.productionTip = false

new Vue({
  render: h => h(App),
}).$mount('#app')

The require used to import echarts here will fail if you use import echarts from 'echarts'. The specific reason is still unknown.

Then write the following code in app.vue:

<template>
  <div id="app">
  </div>
</template>

<script>

export default {
  name: 'App',
  mounted() {
    this.eachartsInit()
  },
  methods: {
    eachartsInit() {
      let myEcharts = this.$echarts.init(document.getElementById("app"))
      let option = {
        legend: {
          data: ["Target 1", "Fixed Type", "Target 2", "Target 3"] //Show how many lines there are, corresponding one to one with the elements of the series array},
        grid: {
          bottom: "20%", //Control the distance between the bottom of the entire chart and the external container width: 800, //
          height:500
        },
        tooltip: {
          trigger: "axis", //Set the mouse to hover over the line to display the X-axis data axisPointer: {
            type: "cross", //Control the display of Y-axis data label: {
              backgroundColor: "#6a7985" //When the mouse moves to this point, add a background color to the coordinates of the coordinate axis}
          }
        },
        xAxis:
          type: "category", //The possible values ​​are time, value, log, category. Category is used for this kind of scatter line chart //The coordinate value of the X-axis data: ["2021.10.28 09:17:34", "2021.10.28 09:20:35", "2021.10.28 09:20:50", "2021.10.28 09:21:05", "2021.10.28 09:22:34", "2021.10.28 09:25:34"],

          //Here controls the font rotation of the X-axis coordinate (counterclockwise)
          axisLabel: {
            rotate: 45, //Degree of rotation color: "red", //Control the font color of the X-axis coordinate fontWeight: 600 //Control the boldness of the font}
          
        },
        //Configuration of the y-axis. Here, y only needs to display the value, and type uses value.
        yAxis: {
          type: "value"
        },
        //
        series: [
          //4 array elements are equivalent to 4 lines {
            data: [820, 750, 450, 560, 650, 660], //The value corresponding to each X coordinate type: "line", //Display type name: "Target 1", //The value of the name attribute is taken from the data array element in legend smooth: true //Whether to perform smoothing },
          {
            data: [220, 450, 350, 760, 680, 560],
            type: "line",
            name: "Target 2",
            smooth: true
          },
          {
            data: [352, 550, 370, 560, 420, 590],
            type: "line",
            name: "Fixed Type",
            smooth: true
          },
          {
            data: [522, 345, 450, 458, 592, 485],
            type: "line",
            name: "Target 3",
            smooth: true
          }
        ]
      }

      myEcharts.setOption(option) // Pass the configuration option to the generated echarts instance
    }
  }
}
</script>

<style>
#app{
  width: 850px;
  height: 600px;
}
</style>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Vue uses echarts scatter plot to mark points in the area

<<:  Tutorial on deploying springboot package in linux environment using docker

>>:  40+ Beautiful Web Form Design Examples

Recommend

A detailed explanation of the subtle differences between Readonly and Disabled

Readonly and Disabled both prevent users from chan...

MySQL users and permissions and examples of how to crack the root password

MySQL Users and Privileges In MySQL, there is a d...

Detailed example of jQuery's chain programming style

The implementation principle of chain programming...

Steps to install MySQL on Windows using a compressed archive file

Recently, I need to do a small verification exper...

MySQL 5.7.18 release installation guide (including bin file version)

The installation process is basically the same as...

Solution to the problem of installing MySQL compressed version zip

There was a problem when installing the compresse...

The difference between method=post/get in Form

Form provides two ways of data transmission - get ...

Why the table file size remains unchanged after deleting data in MySQL

For databases that have been running for a long t...

MySQL common backup commands and shell backup scripts sharing

To back up multiple databases, you can use the fo...

Solve the problem of no my.cnf file in /etc when installing mysql on Linux

Today I wanted to change the mysql port, but I fo...

Detailed tutorial on installing Docker on Windows

Since my local MySQL version is relatively low, I...

Detailed explanation of JavaScript axios installation and packaging case

1. Download the axios plugin cnpm install axios -...

A brief understanding of the three principles of adding MySQL indexes

1. The Importance of Indexes Indexes are used to ...