Vue+echart realizes double column chart

Vue+echart realizes double column chart

This article shares the specific code of vue+echart to realize the double column chart for your reference. The specific content is as follows

Effect picture:

1. Installation

The recommended version is "echarts": "^4.8.0". If it is other than echarts, init will report an error.

1. First, you need to install the echarts dependency package

npm install --save [email protected]

2. Or use the domestic Taobao mirror:

npm install -g cnpm --registry=https://registry.npm.taobao.org
<template>
  <div class="echarts_con">
    <div
      class="echarts_main"
      ref="dialog_root"
      title="Node indicators"
      @close="hideData()"
    >
      <!--Load Condition-->
      <div
        ref="bar_dv"
        :style="{
          width: '100%',
          minHeight: '300px',
        }"
      ></div>
    </div>
  </div>
</template>
 
<script>
import echarts from 'echarts'
// import myIcon from './image/hot_icon.png' // custom icon // import averageIcon from './image/hot_icon.png'
export default {
  name: "Echarts",
  data () {
    return {
      maxStr: 400,
      yInterval: 80,
      myData: [122, 45, 67, 78, 46],
      averageData: [32, 34, 6, 73, 84, 40]
    }
  },
  //If data is passed in from outside, you need to monitor the data start
  // props: {
  // myData: {
  // type: Array,
  // default: []
  // },
  // averageData: {
  // type: Array,
  // default: []
  // }
  // },
  // computed: {
  // address () {
  // const { myData, averageData } = this
  // return {
  // myData,
  // averageData
  // }
  // }
  // },
  // watch: {
  // address: {
  // handler: function (val) {
  // this.compare(val.myData, val.averageData)
  // let newArr = val.myData.concat(val.averageData)
  // let maxNum = Math.max(...newArr)
  // this.maxStr = maxNum
  // if (maxNum >= 500) {
  // this.yInterval = 200
  // } else {
  // this.yInterval = 50
  // }
  // this.drawLine(val.myData, val.averageData)
  // },
  // deep: true

  // }
  // },
  // mounted () {
  // this.$nextTick(function () {
  // this.drawLine();
  // });
  // },
  //If data is passed in from outside, you need to monitor the data end

  mounted () {
    this.drawLine(this.myData, this.averageData)
  },
  methods: {
    //If the one-to-one corresponding data is lower than the average, then prompt compare (arr1, arr2) {
      if (arr1[0] < arr2[0]) {
        this.isCompare = true
      } else if (arr1[1] < arr2[1]) {
        this.isCompare = true
      } else if (arr1[2] < arr2[2]) {
        this.isCompare = true
      } else if (arr1[3] < arr2[3]) {
        this.isCompare = true
      } else {
        this.isCompare = false
      }
    },
    clickClose () {
      this.isCompare = false
    },
    /*Load status icon*/
    drawLine(a, b) {
      var myData = a;
      var averageData = b;
      let bar_dv = this.$refs.bar_dv;
      let myChart = echarts.init(bar_dv);
      var autoHeight = parseInt(this.maxStr / 100) * 10 + 100;
      myChart.getDom().style.height = autoHeight + "px";
      myChart.resize(); //Adaptive height // Draw chart myChart.setOption({
        title: { text: 'Report display' },
        grid: {
          // left: 40,
          containLable: true
        },
        tooltip: {},
        xAxis:
          data: ["Viewed my profile", "Communicated with", "Received resume", "Number of people exposed"],
          axisLine: {
            lineStyle:
              type: 'solid',
              color: '#eeeeee', //color of the left line of x fontSize: 13,
              width: '0.5' //width of the coordinate line}
          },
          axisLabel: { //x-axis font textStyle: {
              color: '#333333',
              fontSize: 13
            }
          },
        },
        yAxis: {
          type: 'value',
          min: 0,
          max: this.maxStr,
          interval: this.yInterval,
          axisLine: {
            lineStyle:
              type: 'solid',
              color: '#fff', //color of the left line width: '0.5' //width of the coordinate line}
          },
          axisLabel: {
            textStyle: {
              color: '#333333',
              fontSize: 13
            }
          },
          splitLine: {
            show: true,
            lineStyle:
              color: ['#eeeeee'],
              width: 1,
              type: 'solid'
            }
          }

        },
        legend: {
          itemWidth: 11,
          itemHeight: 12,
          symbolKeepAspect: true,
          textStyle: {
            fontSize: 11,
            lineHeight: 0,
            backgroundColor: "rgba(11, 164, 19, 1)"
          },
          // icon: `image://${averageIcon}`,

          data: [
            {
              name: 'My',
              // icon: `image://${myIcon}`//custom small icon},
            {
              name: 'Industry Average',
              // icon: `image://${averageIcon}`
            }
          ],
          align: 'left',
          right: 40,
          top: '0',
          textStyle: {
            fontSize: 12,
            textAlign: 'center',
            color: '#333333',
            magrinRight: 3
          },
        },
        series: [{
          name: 'My',
          type: 'bar',
          data: myData,
          barWidth: 16, //column width barGap: '50%', //spacing label: {
            show: true,
            position: 'top',
            textStyle: {
              color: '#4695F3'
            },
            formatter: function (params) {
              return params.value
            }
          },
          itemStyle: {
            normal: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                offset: 0,
                color: '#A5CCF6'
              }, {
                offset: 1,
                color: '#4695F3'
              }]),
              barBorderRadius: [4, 4, 0, 0],
            }
          }
        },
        {
          name: 'Industry Average',
          type: 'bar',
          data: averageData,
          barWidth: 16,
          barGap: '50%',
          label: {
            show: true,
            position: 'top',
            textStyle: {
              color: '#FE8401'
            },
            formatter: function (params) {
              return params.value
            }
          },
          itemStyle: {
            normal: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                offset: 0,
                color: '#FFB235'
              }, {
                offset: 1,
                color: '#FE8401'
              }]),
              barBorderRadius: [4, 4, 0, 0],
            },
            emphasis:
              barBorderRadius: 30
            },
          }
        }
        ]
      }, true);
    },

    hideData() {
      this.$emit("hideDialog")
    },

    confirm () {
      this.hideData();
    },

  }
}
</script>
 
<style scoped>
.echarts_con {
  width: 100%;
  margin: 0 auto;
  margin-top: 8px;
  border-radius: 20px;
  background: #fff;
  padding-bottom: 35px;
}
.echarts_main {
  width: 100%;
  margin: 0 auto;
  padding-top: 20px;
  margin-bottom: -32px;
  margin-right: 20px;
  margin-left: 20px;
}
.bottom {
  width: 90%;
  margin: 0 auto;
  background: #fef8e1;
  border-radius: 6px;
  height: 100%;
  margin-top: 16px;
}
.bottom_con {
  width: 90%;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 34px;
  line-height: 34px;
}
.bottom_text {
  height: 34px;
  line-height: 34px;
  font-size: 13px;
  font-family: PingFang, PingFang-SC;
  font-weight: SC;
  text-align: left;
  color: #fa5d1d;
}
.right_close {
  width: 13px;
  height: 13px;
}
</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+Echart realizes three-dimensional column chart
  • Vue uses Echart icon plug-in bar chart
  • Detailed explanation of vue using Echarts to draw a bar chart
  • Vue+Echart bar chart realizes epidemic data statistics
  • Vue echarts realizes horizontal bar chart
  • Vue implements horizontal beveled bar chart
  • Vue+echarts realizes stacked bar chart
  • Vue+echarts realizes progress bar histogram
  • Vue uses Echarts to implement a three-dimensional bar chart
  • Vue+ Antv F2 realizes stacked bar chart

<<:  IDEA reports an error when connecting to MySQL! Server returns invalid timezone. Go to tab and set serverTimezone property

>>:  Xftp download and installation tutorial (graphic tutorial)

Recommend

Detailed explanation of transaction isolation levels in MySql study notes

background When we talk about transactions, every...

Practical record of optimizing MySQL tables with tens of millions of data

Preface Let me explain here first. Many people on...

js to achieve waterfall flow layout (infinite loading)

This article example shares the specific code of ...

How to install and modify the initial password of mysql5.7.18 under Centos7.3

This article shares with you the installation of ...

How to use JavaScript to get the most repeated characters in a string

Table of contents topic analyze Objects of use So...

Complete steps for mounting a new data disk in CentOS7

Preface I just bought a new VPS. The data disk of...

A brief discussion on the lock range of MySQL next-key lock

Preface One day, I was suddenly asked about MySQL...

Example code for configuring monitoring items and aggregated graphics in Zabbix

1. Install Zabbix Agent to monitor the local mach...

Do you know the difference between empty value and null value in mysql

Preface Recently I found that my friend's met...

MySQL 8.0.20 winx64 installation and configuration method graphic tutorial

This article shares with you the installation and...

Docker-compose installation yml file configuration method

Table of contents 1. Offline installation 2. Onli...

Vue3.0 handwritten carousel effect

This article shares the specific code of Vue3.0 h...

Linux unlink function and how to delete files

1. unlink function For hard links, unlink is used...