• 百度echart的几种动画写法


    1.柱形图

    <template>
      <div class="gwtj-echart">
        <div class="eachert-box" id="street-hdcs-echart"
        @mouseout="mouseout"
        @mouseover="mouseover"
        
        ></div>
      </div>
    </template>
    
    <script>
    import { getActivitiesSummary } from "@/api/module/lqdjScreen";
    import * as echarts from "echarts";
    export default {
      name: "gwtjEchart",
      data() {
        return {
          chartDom: null,
          timgerId: null,
          nowIndex: 0,
          rowNameArr: [],
          rowValueArr: [],
          rowValueArr1:[]
        };
      },
      props: {
        unid: String,
        communityName:String
      },
      mounted() {
        this.getData();
      },
      methods: {
        random(min, max) {
     
         return Math.floor(Math.random() * (max - min)) + min;
     
        },
        getData() {
         
          getActivitiesSummary({
            communityName: this.communityName,
          }).then((res) => {
            if (res.code == 200) {
              let tampArr = res.result.everyMonthActices || [];
              this.rowNameArr = [];
              this.rowValueArr = [];
              tampArr.forEach((item) => {
                // this.weekArr.push(item.counts);
              
                 this.rowNameArr.push(item.month);
                 this.rowValueArr.push(item.total);
                //  this.rowValueArr.push(this.random(1, 100));
              });
             
              // this.init(this.rowNameArr, this.rowValueArr);
              this.startAnimation();
            }
          });
        },
        init(nameArr, valueArr) {
          this.chartDom = echarts.init(document.getElementById("street-hdcs-echart"));
          const option = {
            title: {
              text: "",
            },
            tooltip: {
              trigger: "axis",
              axisPointer: {
                type: "shadow",
              },
            },
            legend: {
              data: ["活动次数"],
              top: "5%",
              right: "5%",
              orient: "horizontal",
              textStyle: {
                fontSize: 12,
                fontWeight: 400,
                color: "#fff",
              },
            },
            grid: {
              left: "3%",
              right: "4%",
              bottom: "3%",
              containLabel: true,
            },
            xAxis: {
              type: "value",
              // boundaryGap: [0, 0.01],
              axisLine: {
                lineStyle: {
                  color: "#fff",
                },
              },
               splitLine: {
                  show: false,
              },
            },
            yAxis: {
              type: "category",
              data: nameArr,
              axisLine: {
                lineStyle: {
                  color: "#fff",
                },
              },
              splitLine: {
                  show: false,
              }
            },
            series: [
              {
                name: "组织活动次数",
                type: "bar",
                data: valueArr,
                // color: "#0263FF",
                itemStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(
                        0, 0, 1, 0,
                        [
                            {offset: 0, color: '#df2c1e'},                   //柱图渐变色
                            {offset: 0.5, color: '#e9713d'},                 //柱图渐变色
                            {offset: 1, color: '#f7cc66'},                   //柱图渐变色
                        ]
                    )
                 }
                }
                
              }
            ],
          };
          this.chartDom.setOption(option);
    
          window.addEventListener("resize", () => {
            this.chartDom.resize();
          });
           this.chartDom.on("click", (params) => {
            console.log(params);
            this.$router.push({
              path: "/bigScreen/communityBig",
              query: {
                communityName: params.name,
                isFull:this.isFull
              },
            });
          });
        },
         mouseover() {
      
          clearInterval(this.timgerId);
        },
        mouseout() {
          this.startAnimation();
        },
        startAnimation() {
          //初始化图表
          // this.nowIndex = 8;
          var that=this;
          let tampNameArr = [];
          let tampValueArr = [];
          this.rowNameArr.forEach((item, index) => {
           
              tampNameArr.push(item);
              tampValueArr.push(this.rowValueArr[index]);
            
          });
    
          this.init(tampNameArr, tampValueArr);
    
          //开启定时任务
          clearInterval(this.timgerId);
          that.timgerId = setInterval(() => {
            tampNameArr.shift();
            tampValueArr.shift();
            tampNameArr.push(that.rowNameArr[this.nowIndex]);
            tampValueArr.push(that.rowValueArr[this.nowIndex]);
    
            that.nowIndex++;
            if (that.nowIndex >= that.rowNameArr.length) {
              that.nowIndex = 0;
            }
            that.chartDom.setOption({
              yAxis: [
                {
                  data: tampNameArr,
                },
              ],
              series: [
                {
                  data: tampValueArr,
                },
              ],
            });
          }, 2000);
        },
      },
    };
    </script>
    
    <style lang="less" scoped>
    .gwtj-echart {
      width: 100%;
      height: 100%;
      position: relative;
      .eachert-box {
        position: absolute;
        width: 90%;
        height: 90%;
        top: 0;
        left: 0;
      }
    }
    </style>
    
    ```javascript
    在这里插入代码片
    
    • 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

    2.线型图表

    <template>
      <div class="gwtj-echart">
        <div class="eachert-box" id="gwtj-echart"></div>
      </div>
    </template>
    
    <script>
    import { getybdyNum } from "@/api/module/lqdjScreen";
    import * as echarts from "echarts";
    export default {
      name: "gwtjEchart",
      data() {
        return {
          chartDom: null,
          timgerId: null,
          nowIndex: 2,
          rowNameArr: [],
          rowValueArr: [],
        };
      },
      props: {
        unid: String,
      },
      mounted() {
        this.getData();
      },
      methods: {
        getData() {
          getybdyNum({
            areaUnid: this.unid,
          }).then((res) => {
            if (res.code == 200) {
              let tampArr = res.result || [];
              this.rowNameArr = [];
              this.rowValueArr = [];
              tampArr.forEach((item) => {
                this.rowNameArr.push(item.title);
                this.rowValueArr.push(item.value.number);
              });
              // this.init(this.nameArr, this.valueArr);
              this.startAnimation();
            }
          });
        },
        init(nameArr, valueArr) {
          this.chartDom = echarts.init(document.getElementById("gwtj-echart"));
          const option = {
            color: ["#ef7100", "#64c06c", "#f4cd49", "#e05667", "#8c5fe8"],
            tooltip: {
              backgroundColor: "#033b77",
              borderColor: "#ef7100",
              textStyle: {
                color: "#fff",
                fontSize: 13,
              },
              trigger: "item",
              formatter: "{b0}:{c0}人",
            },
            xAxis: [
              {
                type: "category",
                boundaryGap: false,
                data: nameArr,
                axisLabel: {
                  overflow: "break",
                  width: 80,
                  show: true,
                  interval: 0,
                },
                axisLine: {
                  lineStyle: {
                    color: "#fff",
                  },
                },
              },
            ],
            yAxis: [
              {
                type: "value",
                color: "#fff",
                axisLine: {
                  lineStyle: {
                    color: "#fff",
                  },
                },
                splitLine: {
                  show: false,
                },
              },
            ],
            series: [
              {
                type: "line",
                areaStyle: {
                  normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                      {
                        offset: 0,
                        color: "rgba(229,56,0 , 0.4)",
                      },
                      {
                        offset: 1,
                        color: "rgba(248,152,5, 0.4)",
                      },
                    ]),
                  },
                },
                barGap: 0,
                // label: labelOption,
                emphasis: {
                  focus: "series",
                },
                data: valueArr,
              },
            ],
          };
          this.chartDom.setOption(option);
          window.addEventListener("resize", () => {
            this.chartDom.resize();
          });
        },
        startAnimation() {
          //初始化图表
          this.nowIndex = 3;
          let tampNameArr = [];
          let tampValueArr = [];
          this.rowNameArr.forEach((item, index) => {
            if (index < this.nowIndex) {
              tampNameArr.push(item);
              tampValueArr.push(this.rowValueArr[index]);
            }
          });
    
          this.init(tampNameArr, tampValueArr);
    
          //开启定时任务
          clearInterval(this.timgerId);
          this.timgerId = setInterval(() => {
            tampNameArr.shift();
            tampValueArr.shift();
            tampNameArr.push(this.rowNameArr[this.nowIndex]);
            tampValueArr.push(this.rowValueArr[this.nowIndex]);
    
            this.nowIndex++;
            if (this.nowIndex >= this.rowNameArr.length) {
              this.nowIndex = 0;
            }
            this.chartDom.setOption({
              xAxis: [
                {
                  data: tampNameArr,
                },
              ],
              series: [
                {
                  data: tampValueArr,
                },
              ],
            });
          }, 2000);
        },
      },
      beforeDestroy() {
        clearInterval(this.timgerId);
      },
    };
    </script>
    
    <style lang="less" scoped>
    .gwtj-echart {
      width: 100%;
      height: 100%;
      position: relative;
      .eachert-box {
        position: absolute;
        width: 100%;
        height: 110%;
        top: 0;
        left: 0;
      }
    }
    </style>
    
    • 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

    3.饼状图

    <template>
      <div class="kq-echart">
        <div
          class="eachert-box"
          id="kq-echart"
          @mouseout="mouseout"
          @mouseover="mouseover"
        ></div>
      </div>
    </template>
    
    <script>
    import moment from "moment";
    import { getDyStatus } from "@/api/module/lqdjScreen";
    import * as echarts from "echarts";
    export default {
      name: "kqEchart",
      data() {
        return {
          nowIndex: 0,
          timer: null,
          chartDom: null,
        };
      },
      mounted() {
        this.getData();
      },
      methods: {
        getData() {
          getDyStatus({
            dkrq: moment().format("YYYY-MM-DD"),
          }).then((res) => {
            if (res.code == 200) {
              let tampArr = res.result || [];
              let data = [];
              tampArr.forEach((item) => {
                data.push({
                  value: item.value.number,
                  name: item.title,
                });
              });
              this.init(data);
            }
          });
        },
        init(data) {
          this.chartDom = echarts.init(document.getElementById("kq-echart"));
          const option = {
            color: [
              "#fc7b04",
              "#FF7D00",
              "#8781D7",
              "#FFC83B",
              "#FFA800",
              "#c11200",
              "#1304D3",
              "#c11200",
            ],
            tooltip: {
              backgroundColor: "#033b77",
              borderColor: "#21f2c4",
              textStyle: {
                color: "#fff",
                fontSize: 13,
              },
              trigger: "item",
              formatter: "{b0}:{d}%",
            },
            legend: {
              top: "center",
              left: "10%",
              orient: "vertical",
              textStyle: {
                color: "#fff",
              },
            },
            series: [
              {
                name: "考勤",
                type: "pie",
                top: "20",
                left: "30%",
                radius: ["40%", "70%"],
                avoidLabelOverlap: false,
                label: {
                  show: false,
                  position: "center",
                },
                emphasis: {
                  itemStyle: {
                    shadowColor: "rgba(255, 255, 255, 0.9)",
                    shadowBlur: 20,
                  },
                  label: {
                    show: true,
                    fontSize: "18",
                    fontWeight: "bold",
                    color: "#fff",
                    formatter: "{b}\n{c}人",
                  },
                },
                labelLine: {
                  show: false,
                },
                data: data,
              },
            ],
          };
          this.chartDom.setOption(option);
    
          this.chartDom.dispatchAction({
            type: "highlight",
            seriesIndex: 0,
            dataIndex: this.nowIndex,
          });
    
          clearInterval(this.timer);
          this.timer = setInterval(() => {
            this.chartDom.dispatchAction({
              type: "downplay",
              seriesIndex: 0,
              dataIndex: [0, 1, 2, 3],
            });
            this.nowIndex++;
            if (this.nowIndex > 3) {
              this.nowIndex = 0;
            }
            this.chartDom.dispatchAction({
              type: "highlight",
              seriesIndex: 0,
              dataIndex: this.nowIndex,
            });
          }, 3000);
    
          window.addEventListener("resize", () => {
            this.chartDom.resize();
          });
        },
        mouseover() {
          this.chartDom.dispatchAction({
            type: "downplay",
            seriesIndex: 0,
            dataIndex: [0, 1, 2, 3],
          });
          clearInterval(this.timer);
        },
        mouseout() {
          this.chartDom.dispatchAction({
            type: "highlight",
            seriesIndex: 0,
            dataIndex: this.nowIndex,
          });
          this.timer = setInterval(() => {
            this.chartDom.dispatchAction({
              type: "downplay",
              seriesIndex: 0,
              dataIndex: [0, 1, 2, 3],
            });
            this.nowIndex++;
            if (this.nowIndex > 3) {
              this.nowIndex = 0;
            }
            this.chartDom.dispatchAction({
              type: "highlight",
              seriesIndex: 0,
              dataIndex: this.nowIndex,
            });
          }, 3000);
        },
      },
      beforeDestroy() {
        clearInterval(this.timer);
      },
    };
    </script>
    
    <style lang="less" scoped>
    .kq-echart {
      width: 100%;
      height: 100%;
      position: relative;
      .eachert-box {
        width: 100%;
        height: 100%;
      }
    }
    </style>
    
    • 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
  • 相关阅读:
    2023亚太杯数学建模A题B题C题思路模型代码论文指导
    Java安全--篇2-类的动态加载
    在 HarmonyOS 上使用 ArkUI 实现计步器应用
    Qt入门(四)——连续播放图片(两种定时器的运用)
    算法——滑动窗口
    1.3数据结构之复杂度 力扣题目移除元素
    HBase简介
    Profinet总线模拟输出模块
    ESP32-CAM初始篇:Arduino环境搭建-->实现局域网推流
    【干货】安全应用RPA的3个阶段
  • 原文地址:https://blog.csdn.net/duancsdn/article/details/126877589