• ECharts柱状图加滚动条


    在这里插入图片描述

    <template>
      <div
        :class="className"
        :style="{ height: height, width: width, 'min-height': minHeight }"
      />
    template>
    
    <script>
    import echarts from "echarts";
    import { debounce } from "@/utils";
    require("echarts/theme/macarons"); // echarts theme
    import "echarts-liquidfill";
    
    const animationDuration = 6000;
    
    export default {
      props: {
        className: {
          type: String,
          default: "chart",
        },
        width: {
          type: String,
          default: "100%",
        },
        height: {
          type: String,
          default: "10rem",
        },
        minHeight: {
          type: String,
          default: "5rem",
        },
        param: {
          type: Array,
          default: () => {},
        },
      },
      data() {
        return {
          chart: null,
        };
      },
      watch: {
        param: {
          handler: function (value) {
            this.$nextTick((_) => {
              this.initChart();
            });
          },
          immediate: true,
        },
      },
      mounted() {
        this.$nextTick(() => {
          this.initChart();
        });
        this.__resizeHandler = debounce(() => {
          if (this.chart) {
            this.chart.resize();
          }
        }, 100);
        window.addEventListener("resize", this.__resizeHandler);
      },
      beforeDestroy() {
        if (!this.chart) {
          return;
        }
        window.removeEventListener("resize", this.__resizeHandler);
        this.chart.dispose();
        this.chart = null;
      },
      methods: {
        initChart() {
          let color = this.$store.state.color.colorListPars;
          this.chart = echarts.init(this.$el, "macarons");
          let dataName = [];
          let dataNum = [];
          let completeNum = [];
          let scatteredNum = [];
          this.param.map((item) => {
            dataName.push(item.staffName);
            dataNum.push(parseFloat(Number(item.num).toFixed(0)));
            completeNum.push(parseFloat(Number(item.completeNum).toFixed(0)));
            scatteredNum.push(parseFloat(Number(item.scatteredNum).toFixed(0)));
          });
          let option = {
            color: ["#2394ef"],
            grid: {
              left: "1px",
              bottom: "0px",
              top: "10px",
              containLabel: true,
            },
            xAxis: {
              type: "category",
              axisLine: { lineStyle: { color: "#EFEFEF" } },
              axisLabel: {
                textStyle: {
                  //改变刻度字体样式
                  color: color,
                  fontSize: 12,
                },
                formatter: function (value) {
                  return value.split("").join("\n");
                },
              },
              data: dataName,
            },
            legend: {
              orient: "vertical",
              top: 0,
              right: 0,
              itemWidth: 10,
              itemHeight: 10,
              icon: "circle",
              data: ["整件", "零散"],
            },
            tooltip: {
              trigger: "axis",
              axisPointer: {
                // 坐标轴指示器,坐标轴触发有效
                type: "shadow", // 默认为直线,可选为:'line' | 'shadow'
              },
              formatter: function (params, ticket, callback) {
                //格式化函数
                return (
                  "总数量:" +
                  parseFloat(Number(params[0].data + params[1].data).toFixed(0)) +
                  "件
    整件:"
    + parseFloat(Number(params[0].data).toFixed(0)) + "件
    零散:"
    + parseFloat(Number(params[1].data).toFixed(0)) + "件" ); }, }, yAxis: { axisLabel: { color: color, formatter: "{value}件", }, axisLine: { show: true, lineStyle: { color: "#FFFFFF" } }, }, // dataZoom: [ // { // show: true, // start: 0, // end: 100 // }, // { // type: 'inside', // start: 0, // end: 100 // }, // ], series: [ { name: "整件", type: "bar", stack: "total", // ! 多条数据总计 => 堆叠 barWidth: 24, color: "#2D8EFF", itemStyle: { borderRadius: 0 }, data: completeNum, }, { name: "零散", type: "bar", stack: "total", // ! 多条数据总计 => 堆叠 barWidth: 24, color: "#CAE1FF", itemStyle: { borderRadius: [12, 12, 0, 0] }, data: scatteredNum, }, { data: dataNum, type: "line", emphasis: { focus: "series", }, barWidth: 1, lineStyle: { color: "transparent", }, symbol: "none", markLine: { data: [ { type: "average", name: "平均值", }, ], }, }, ], }; if (this.param.length > 20) { option.dataZoom = [ { type: "slider", show: true, xAxisIndex: [0], start: 0, end: 20, textStyle: { color: "#ccd7d7", }, filterMode: "empty", bottom: 14, }, ]; } if (option && typeof option == "object") { this.chart.setOption(option); } }, }, };
    script>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
  • 相关阅读:
    YOLOv5的Tricks | 【Trick14】YOLOv5的val.py脚本的解析
    Flask 学习-55.文件上传功能开发
    css属性clip-path的使用说明
    PyTorch:张量与矩阵
    【Java面试题】cookie和session的区别
    湖南衡阳3D扫描在生物仿真研究的应用高精度三维扫描螃蟹-CASAIM中科广电
    【目标检测】yolov5的pth模型转onnx及模型推理
    【混沌工程】混沌工程原理
    【开题报告】基于SpringBoot的美术馆预约平台的设计与实现
    使用js搭建简易的WebRTC实现视频直播
  • 原文地址:https://blog.csdn.net/weixin_42268006/article/details/128157795