1.配置echarts环境

1.1安装echarts

npm install echarts --save

1.2 在main.js全局引入

import Vue from 'vue'
import * as echarts from "echarts";//引入echarts
Vue.prototype.$echarts = echarts//挂载到vue实例,方便全局使用

导入方法不对,会引起报错,显示’init’ of undefined

1.2.1echarts5.0及以上版本

import *as echarts from 'echarts'//引入echarts
//或者
let echarts = require('echarts')//引入echarts

1.2.2echarts5.0版本以下

import echarts from 'echarts'//引入echarts
//或者
import *as echarts from 'echarts'//引入echarts
//或者
let echarts = require('echarts')//引入echarts

2.echarts的使用

2.1 echarts5.0及以上版本

import * as echarts from "echarts";

2.2 echarts5.0以下版本

import echarts from "echarts";

2.3使用

在这里插入图片描述

<div id="LeadershipScreen6" class="myecharts" style="width: 100%;height: 70%;display:inline-block;background:rgb(246, 249, 255)"></div>
mounted() {
    this.LeadershipScreen6();
  },
  // 方法集合
  methods: {
  //进度条
    LeadershipScreen6() {
      let LeadershipScreen6 = echarts.init(
        document.getElementById("LeadershipScreen6")
      );
      let ratioNumber = [80];

      LeadershipScreen6.setOption({
        grid: {
          left: "5%",
          right: "5%",
          bottom: "5%",
          top: "10%",
          containLabel: true,
        },
        backgroundColor: "transparent",
        // xAxis: {
        //     show: false,
        //     type: 'value',
        //     max: 100,
        // },
        xAxis: [
          {
            type: "value",
            axisLabel: {
              margin: 5,
              color: "#fff",
              formatter: function (val) {
                return val + "";
              },
              textStyle: {
                fontSize: "0",
              },
            },
            min: 0,
            max: 100, // 计算最大值
            // interval: max / 5, //  平均分为5份
            splitNumber: 15,
            splitLine: {
              show: false,
              lineStyle: {
                color: "#fff",
              },
            },
            axisLine: {
              show: false,
              lineStyle: {
                color: "#fff",
                width: 1,
                opacity: 0.3,
              },
            },
            axisTick: {
              show: false,
            },
          },
          {
            type: "value",
            axisLabel: {
              show: false,
            },
            min: 0,
            max: 100, // 计算最大值
            interval: 100 / 10, //  平均分为5份
            splitNumber: 10,
            splitLine: {
              show: false,
              lineStyle: {
                type: "dashed",
                color: "#D8D8D8",
              },
            },
            axisLine: {
              show: false,
              lineStyle: {
                color: "#fff",
              },
            },
            axisTick: {
              show: false,
            },
          },
        ],
        yAxis: [
          {
            type: "category",
            inverse: true,
            axisLabel: {
              show: false,
              textStyle: {
                fontSize: "12",
                color: "#03fcfe",
              },
            },
            splitLine: {
              show: false,
            },
            axisTick: {
              show: false,
            },
            axisLine: {
              show: false,
            },
            data: ["比率"],
          },
          {
            type: "category",
            inverse: true,
            axisTick: "none",
            axisLine: "none",
            show: false,
            data: ratioNumber, //80
          },
        ],
        series: [
          {
            type: "bar",
            showBackground: false,
            xAxisIndex: 0,
            backgroundStyle: {
              color: "transparent",
              borderRadius: 30,
              z: 1212,
            },
            label: {
              show: true,
              position: "right",
              formatter: "{@score}%",
              textStyle: {
                color: "rgb(25, 142, 248)",
                fontSize: "16",
              },
            },
            itemStyle: {
              normal: {
                barBorderRadius: 20,
                color: "rgb(25, 142, 248)",
              },
            },
            barWidth: 20,
            data: ratioNumber, //80
            z: 12212,
          },
          {
            type: "bar",
            showBackground: false,
            xAxisIndex: 1,
            barGap: "-100%",
            backgroundStyle: {
              color: "transparent",
              borderRadius: 30,
              z: 1212,
            },
            label: {
              show: false,
              position: "right",
              formatter: "{@score}%",
              textStyle: {
                color: "#fff",
                fontSize: "12",
              },
            },
            itemStyle: {
              normal: {
                barBorderRadius: 20,
                color: "rgba(215, 236, 255,.4)",
              },
            },
            barWidth: 20,
            data: [100],
            z: 12210,
          },
        ],
      });

      window.addEventListener("resize", function () {
        LeadershipScreen6.resize();
      });
    },
  },
Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐