Vue echarts realizes dynamic display of bar chart

Vue echarts realizes dynamic display of bar chart

This article shares the specific code of vue echarts to realize the dynamic display of bar chart for your reference. The specific content is as follows

Display in the form of a carousel

<template>
  <div class="dan">
    <div id="scalesize" :style="{width: '100%', height: '100%'}"></div>
  </div>
</template>
<script>
import echarts from "echarts";
export default {
  data() {
    return {
      texts: 111
    };
  },
  mounted() {
    this.drawLine();
  },
  methods: {
    drawLine() {
      // Initialize the echarts instance based on the prepared dom let myChart = this.$echarts.init(document.getElementById("scalesize"));
      var fanfa = [
        {
          name: "Seedling Base",
          type: "bar",
          barWidth: "15%",
          itemStyle: {
            normal: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: "#fccb05"
                },
                {
                  offset: 1,
                  color: "#f5804d"
                }
              ]),
              barBorderRadius: 12
            }
          },
          data: [100, 120, 160, 180, 220, 400]
        },
        {
          name: "Planting Base",
          type: "bar",
          barWidth: "15%",
          itemStyle: {
            normal: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: "#8bd46e"
                },
                {
                  offset: 1,
                  color: "#09bcb7"
                }
              ]),
              barBorderRadius: 11
            }
          },
          data: [270, 320, 420, 650, 821,907]
        },
        {
          name: "Hosted Area",
          type: "bar",
          barWidth: "15%",
          itemStyle: {
            normal: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: "#248ff7"
                },
                {
                  offset: 1,
                  color: "#6851f1"
                }
              ]),
              barBorderRadius: 11
            }
          },
          data: [140, 180, 215, 320, 396, 520]
        },
        {
          name: "Joint Construction Base",
          type: "bar",
          barWidth: "15%",
          itemStyle: {
            normal: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: "#B88080"
                },
                {
                  offset: 1,
                  color: "#983A3A"
                }
              ]),
              barBorderRadius: 11
            }
          },
          data: [140, 180, 215, 320, 396, 420]
        }
      ];
      myChart.setOption({
        tooltip: {
          trigger: "axis",
          axisPointer:
            // Axis indicator, axis trigger valid type: "shadow" // Default is a straight line, optional: 'line' | 'shadow'
          }
        },
        grid: {
          left: "2%",
          right: "4%",
          bottom: "14%",
          top: "16%",
          containLabel: true
        },
        legend: {
          data: ["seedling base", "planting base", "trusteeship area", "joint construction base"],
          right: 10,
          top: 12,
          textStyle: {
            color: "#fff"
          },
          itemWidth: 12,
          itemHeight: 10
          //itemGap: 35
        },
        xAxis:
          type: "category",
          data: [
            "2014",
            "2015",
            "2016",
            "2017",
            "2018",
            "2019"
          ],
          axisLine: {
            lineStyle:
              color: "white"
            }
          },
          axisLabel: {
            // interval: 0,
            // rotate: 40,
            textStyle: {
              fontFamily: "Microsoft YaHei"
            }
          }
        },
        yAxis: {
          type: "value",
          axisLine: {
            show: false,
            lineStyle:
              color: "white"
            }
          },
          splitLine: {
            show: true,
            lineStyle:
              color: "rgba(255,255,255,0.3)"
            }
          },
          axisLabel: {}
        },
        dataZoom: [
          {
            show: true,
            height: 12,
            xAxisIndex: [0],
            bottom: "8%",
            handleIcon:
              "path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z",
            handleSize: "110%",
            handleStyle: {
              color: "#d3dee5"
            },
            textStyle: {
              color: "#fff"
            },
            borderColor: "#90979c"
          },
          {
            type: "inside",
            show: true,
            height: 15,
            start: 1,
            end: 35
          }
        ],
        series: fanfa
      });
      let app = {
        currentIndex: -1
      };
      setInterval(function() {
        let dataLen = fanfa[1].data.length;
        // Cancel the previously highlighted graph myChart.dispatchAction({
          type: "downplay",
          seriesIndex: 0,
          dataIndex: app.currentIndex
        });
        app.currentIndex = (app.currentIndex + 1) % dataLen;
        //console.log(app.currentIndex);
        //Highlight the current graphmyChart.dispatchAction({
          type: "highlight",
          seriesIndex: 0,
          dataIndex: app.currentIndex
        });
        // Display tooltip
        myChart.dispatchAction({
          type: "showTip",
          seriesIndex: 0,
          dataIndex: app.currentIndex
        });
      }, 1000);
      window.onresize = myChart.resize;
    }
  }
};
</script>
<style lang="less" scoped>
.dan {
  height: 90%;
}
</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 Echarts implements column chart with scrolling effect
  • Vue+echarts realizes 3D column chart
  • Vue implements three-dimensional column chart based on echarts
  • Vue uses echarts to implement a horizontal column chart example
  • Implementing a simple column chart using D3.js+Vue
  • Vue uses Echarts to implement a three-dimensional bar chart
  • Vue echarts realizes horizontal bar chart
  • Vue+echarts realizes stacked bar chart
  • How to use bar charts in Vue and modify the configuration yourself
  • Vue uses echarts to implement a three-dimensional column chart

<<:  MySQL 8.0.20 installation and configuration detailed tutorial

>>:  How to connect Xshell5 to Linux in a virtual machine and how to solve the failure

Recommend

How to delete folders, files, and decompress commands on Linux servers

1. Delete folders Example: rm -rf /usr/java The /...

Complete steps to install MySQL 8.0.x on Linux

MySQL Introduction to MySQL MySQL was originally ...

Detailed explanation of how to exit Docker container without closing it

After entering the Docker container, if you exit ...

JavaScript static scope and dynamic scope explained with examples

Table of contents Preface Static scope vs. dynami...

Understand CSS3 FlexBox elastic layout in 10 minutes

Basic Introduction Features Flexbox is a CSS disp...

Vue3 (Part 2) Integrating Ant Design Vue

Table of contents 1. Integrate Ant Design Vue 2. ...

How to set and get the number of Mysql connections

Get the number of connections --- Get the maximum...

Complete steps to build a squid proxy server in linux

Preface This article mainly introduces the releva...

A brief analysis of the use of watchEffect in Vue3

Preface Everyone should be familiar with the watc...

HTML scroll bar textarea attribute setting

1. Overflow content overflow settings (set whether...

How to quickly install RabbitMQ in Docker

1. Get the image #Specify the version that includ...

Problems encountered in the execution order of AND and OR in SQL statements

question I encountered a problem when writing dat...

Example of using swiper plugin to implement carousel in Vue

Table of contents vue - Use swiper plugin to impl...