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

mysql uses stored procedures to implement tree node acquisition method

As shown in the figure: Table Data For such a tre...

Example operation MySQL short link

How to set up a MySQL short link 1. Check the mys...

CentOS 6 Compile and install ZLMediaKit analysis

Install ZLMediaKit on centos6 The author of ZLMed...

Create a custom system tray indicator for your tasks on Linux

System tray icons are still a magical feature tod...

Build a file management system step by step with nginx+FastDFS

Table of contents 1. Introduction to FastDFS 1. I...

What is the length of a function in js?

Table of contents Preface Why How much is it? Num...

Install and configure MySQL under Linux

System: Ubuntu 16.04LTS 1\Download mysql-5.7.18-l...

How to use MySQL binlog to restore accidentally deleted databases

Table of contents 1 View the current database con...

Mobile browser Viewport parameters (web front-end design)

Mobile browsers place web pages in a virtual "...

How to upload the jar package to nexus via the web page

When using Maven to manage projects, how to uploa...

Solution to uninstalling Python and yum in CentOs system

Background of the accident: A few days ago, due t...

Solution to the problem of slow docker pull image speed

Currently, Docker has an official mirror for Chin...

Tomcat common exceptions and solution code examples

The company project was developed in Java and the...