vue大数据可视化【数字滚动效果】

大数据可视化(基于echarts的一些小组件)

数据滚动效果
![在这里插入图片描述](https://img-blog.csdnimg.cn/cb94b075f2514ddfb585924e6ff525c1.pn在这里插入图片描述

根据父组件传参进行数据的滚动,话不多说,直接上代码

	<template>
  <div class="chartNum">
<div class="box-item">
  <li
    :class="{ 'number-item': !isNaN(item), 'mark-item': isNaN(item) }"
    v-for="(item, index) in orderNum"
    :key="index"
  >
    <span v-if="!isNaN(item)">
      <i ref="numberItem">0123456789</i>
    </span>
    <span class="comma" v-else>{{ item }}</span>
  </li>
</div>
  </div>
</template>
<script>
export default {
  props: {
sumStock: {
  type: String
}
  },
  data() {
return {
  orderNum: ["0", "0", "0", "0", "0"] // 默认订单总数
};
  },
  mounted() {
this.$nextTick(() => {
  console.log(this.sumStock, "----");

  this.toOrderNum(Number(this.sumStock)); // 这里输入数字即可调用
  this.setNumberTransform();

  // this.increaseNumber();
});
  },
  watch: {
sumStock(newValue, oldValue) {
  this.toOrderNum(Number(this.sumStock)); // 这里输入数字即可调用
  this.setNumberTransform();
}
  },
  methods: {
// 定时增长数字
increaseNumber() {
  let self = this;
  console.log(self.getRandomNumber(1, 100));
  this.timer = setInterval(() => {
    console.log(self.newNumber);
    this.toOrderNum(self.getRandomNumber(1, 10000));
    self.setNumberTransform();
    // this.toOrderNum(2222);
  }, 3000);
},
getRandomNumber(min, max) {
  return Math.floor(Math.random() * (max - min + 1) + min);
},
// 设置文字滚动
setNumberTransform() {
  const numberItems = this.$refs.numberItem; // 拿到数字的ref,计算元素数量
  const numberArr = this.orderNum.filter(item => !isNaN(item));
  // 结合CSS 对数字字符进行滚动,显示订单数量
  for (let index = 0; index < numberItems.length; index++) {
    const elem = numberItems[index];
    elem.style.transform = `translate(-50%, -${numberArr[index] * 10}%)`;
  }
},
// 处理总订单数字
toOrderNum(num) {
  num = num.toString();
  // 把订单数变成字符串
  if (num.length < 5) {
    num = "0" + num; // 如未满八位数,添加"0"补位
    this.toOrderNum(num); // 递归添加"0"补位
  } else if (num.length === 5) {
    // 订单数中加入逗号
    // num = num.slice(0, 2) + "," + num.slice(2, 5) + "," + num.slice(5, 8);
    this.orderNum = num.split(""); // 将其便变成数据,渲染至滚动数组
  } else {
    // 订单总量数字超过八位显示异常
    this.$message.warning("订单总量数字过大,显示异常,请联系客服");
  }
}
  }
};
</script>
<style scoped lang="scss">
/*订单总量滚动数字设置*/
.box-item {
  position: relative;
  height: 100px;
font-size: 40px;
line-height: 41px;
text-align: center;
list-style: none;
color: #2d7cff;
writing-mode: vertical-lr;
text-orientation: upright;
/*文字禁止编辑*/
-moz-user-select: none; /*火狐*/
-webkit-user-select: none; /*webkit浏览器*/
-ms-user-select: none; /*IE10*/
-khtml-user-select: none; /*早期浏览器*/
user-select: none;

/* overflow: hidden; */
}
/* 默认逗号设置 */
.mark-item {
width: 10px;
height: 100px;
margin-right: 5px;
line-height: 10px;
font-size: 48px;
position: relative;
& > span {
position: absolute;
width: 100%;
bottom: 0;
writing-mode: vertical-rl;
text-orientation: upright;
}
}
/*滚动数字设置*/
.number-item {
width: 41px;
height: 60%;
// background: #ccc;
list-style: none;
margin-right: 5px;
background: linear-gradient(
180deg,
#00f2fe 0%,
rgba(1, 193, 211, 0.77) 8%,
rgba(2, 144, 168, 0.54) 16%,
rgba(3, 103, 132, 0.35) 24%,
rgba(4, 72, 105, 0.2) 32%,
rgba(4, 49, 85, 0.09) 39%,
rgba(4, 35, 73, 0.02) 45%,
rgba(5, 31, 69, 0) 50%,
rgba(4, 37, 74, 0.03) 55%,
rgba(4, 54, 89, 0.11) 62%,
rgba(3, 82, 113, 0.24) 70%,
rgba(2, 121, 148, 0.43) 80%,
rgba(1, 171, 191, 0.66) 90%,
rgba(0, 227, 240, 0.93) 100%
);
opacity: 1;

border-radius: 4px;
// border: 1px solid rgba(221, 221, 221, 1);
& > span {
position: relative;
display: inline-block;
margin-right: 10px;
width: 100%;
height: 100%;
writing-mode: vertical-rl;
text-orientation: upright;
overflow: hidden;
& > i {
font-style: normal;
position: absolute;
top: 11px;
left: 50%;
transform: translate(-50%, 0);
transition: transform 1s ease-in-out;
letter-spacing: 10px;
}
}
}
.number-item:last-child {
margin-right: 0;
}
</style>

根据应用,放在自己该放的地址

父组件如何调用如下:

components: {
number: () => import("对应组件路径"), // 组件懒加载
  },

在这里插入图片描述
对应传参数量 用sumStock 即可传参 ,假如小伙伴需要更改次变量可在子组件修改对应变量

假如对你有用希望点击关注,你的关注也是对博主的一个激励

CSDN私信我,接私活

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值