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

Markup language - web application CSS style

Click here to return to the 123WORDPRESS.COM HTML ...

Linux uses shell scripts to regularly delete historical log files

1. Tools directory file structure [root@www tools...

Ajax jquery realizes the refresh effect of a div on the page

The original code is this: <div class='con...

Docker Machine in-depth explanation

Differences between Docker and Docker Machine Doc...

Docker network mode and configuration method

1. Docker Network Mode When docker run creates a ...

Some tips for writing high-performance HTML applications

How can you improve web page performance? Most de...

How to quickly create tens of millions of test data in MySQL

Remark: The amount of data in this article is 1 m...

Util module in node.js tutorial example detailed explanation

Table of contents Starting from type judgment Str...

How to install mysql in docker

I recently deployed Django and didn't want to...

MySQL 5.6 installation steps with pictures and text

MySQL is an open source small relational database...

Specific method to delete mysql service

MySQL prompts the following error I went to "...

How to fix the WeChat applet input jitter problem

Find the problem Let's look at the problem fi...

JavaScript uses setTimeout to achieve countdown effect

In order to enhance the ability to write JavaScri...