手写echats

<template>
  <div class="progress-bar-wrapper">
    <div style="width: 100%">
      <div class="progress-bar">
        <div style="width: 70px">{{ title }}</div>
        <div class="progress-bar">
          <div
            class="progress-bar-item"
            :class="data.length > 2 ? 'center' : 'justify'"
            v-for="(item, index) in data"
            :key="`progress-bar-${index}`"
            :style="{
              width: getWidth(item.value) + '%',
              background: color[index],
            }"
          ></div>
          <div
            class="progrennbar-item2"
            style="text-align: right"
            :style="{
              width: getWidth1(value1) + '%',
              background: color1[0],
            }"
          >
            <span style="color: #fff; font-size: 16px; margin-right: 20px">{{
              value1
            }}</span>
          </div>
        </div>
      </div>
      <div v-if="totaltext1" style="display: flex; margin-left: 70px">
        <div style="margin-right: 50px">身高:{{ "121cm" }}</div>
        <div>体重:{{ "26kg" }}</div>
      </div>
      <div v-if="totaltext2">
        <div
          class="progress-bar"
          style="
            justify-content: space-around;
            padding-left: 45px;
            margin-top: 20px;
          "
        >
          <div v-for="(item, index) in data" :key="index">
            <div class="progress-bar-txt" style="display: flex">
              <div
                style="width: 16px; height: 16px; margin-right: 5px"
                :style="{
                  background: color[index],
                }"
              ></div>
              {{ item.name }}
            </div>
          </div>
          <div style="display: flex">
            <div
              style="width: 16px; height: 16px; margin-right: 5px"
              :style="{
                background: color1[0],
              }"
            ></div>
            {{ "实际值" }}
          </div>
        </div>
      </div>
    </div>
    <div class="progress-bar-total" v-if="totalText">
      <span style="font-size: 26px">{{ total1 !== 0 ? total1 : total }}</span>
      <span>{{ totalText || "总数" }}</span>
    </div>
  </div>
</template>
<script>
export default {
  name: "progressbarchar",
  props: [
    "data",
    "color",
    "total1",
    "totalText",
    "title",
    "value1",
    "color1",
    "totaltext1",
    "totaltext2",
  ],
  computed: {
    total() {
      let num = 0;
      if (this.data && this.data.length) {
        this.data.forEach((item) => {
          num += item.value;
        });
      }
      return num;
    },
  },
  methods: {
    getWidth(value) {
      return (value / this.total) * 100;
    },
    getWidth1(value) {
      return (value / this.total) * 100;
    },
  },
};
</script>
<style lang="less" scoped>
.progress-bar-wrapper {
  display: flex;
  height: 44px;
  justify-content: space-between;
  .progress-bar {
    position: relative;
    display: flex;
    flex: 1 1;
    align-items: center;
    .progrennbar-item2 {
      position: absolute;
      left: 0;
      top: 50%;
      margin-top: -12.5px;
      height: 21px;
    }
    .progress-bar-item {
      padding: 0 10px;
      position: relative;
      height: 30px;
      line-height: 30px;
      margin-bottom: 5px;
      &:first-child {
        white-space: nowrap;
      }
      &:last-child {
        white-space: nowrap;
      }
      .progress-bar-txt {
        position: absolute;
        top: 100%;
        width: 100%;
      }
      &.center {
        .progress-bar-txt {
          text-align: center;
        }
      }
      &.justify {
        &:last-child {
          text-align: right;
        }
      }
    }
  }
  .progress-bar-total {
    display: flex;
    flex-flow: column;
    width: 24%;
    padding-left: 20px;
    margin-top: -10px;
    span {
      text-align: center;
      &:first-child {
        color: #e64343;
        font-size: 18px;
        font-weight: bold;
      }
      &:last-child {
        color: #333;
        font-size: 12px;
      }
    }
  }
}
</style>

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值