vue中水球图组件

1.Liquidfill.vue

<template>
  <div class="yh-liquidfill"></div>
</template>
<script>
function _update(chart, v) {
  var p = Math.max(0, Math.min(v, 1));
  var second = p > 0.1 ? p : p - 0.05;
  chart.setOption({
    series: [
      {
        name: "liquidFill",
        data: [p, second]
      }
    ]
  });
}

export default {
  name: "YhLiquidfille",
  data() {
    return {
      value: 0
    };
  },
  props: ["init", "color", "size"],
  watch: {
    value(v) {
      _update(this.$chart, v);
    }
  },
  methods: {},
  mounted() {
    var chart = echarts.init(this.$el);
    var wcolor = ["#663300", "#ffcc99"];
    var bdcolor = "#663300";
    var lcolor = "#663300";
    var bgcolor = "#e3e7ff";
    var c = this.color;
    if (c) {
      wcolor = c.wave || wcolor;
      bdcolor = c.border || bdcolor;
      lcolor = c.label || lcolor;
      bgcolor = c.background || bgcolor;
    }
    var option = {
      series: [
        {
          type: "liquidFill",
          name: "liquidFill",
          color: wcolor,
          outline: {
            show: true,
            borderDistance: 8,
            itemStyle: {
              color: "none",
              borderColor: bdcolor,
              borderWidth: 8,
              shadowBlur: 20,
              shadowColor: "rgba(0, 0, 0, 0.25)"
            }
          },
          backgroundStyle: {
            color: bgcolor
          },
          label: {
            color: lcolor
          },
          data: []
        }
      ]
    };
    chart.setOption(option);
    var v = this.init;
    if (this.init) {
      this.value = v;
    }
    this.$chart = chart;
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>

2.LiquidfillDemo.vue

<template>
  <div class="yh-page">
    <h1>水球图演示</h1>
    <div class="desc">Demo源代码:
      <code>/examples/components/modules/LiquidfillDemo.vue</code>
    </div>
    <div style="margin-top:20px;width:400px;">
      <el-form label-width="80px">
        <el-form-item label="百分比">
          <el-input v-model="value" type="number" value="0.6" min="0" max="1" @change="onChange"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <yh-liquidfill :init="0.6" ref="lf" :color="color"></yh-liquidfill>
  </div>
</template>
<script>
import liquidfill from "../../components/comcompont/echarts/Liquidfill";
export default {
  name: "LiquidfillDemo",
  data() {
    return {
      value: 0.6,
      color: {
        wave: ["#036", "#069"],
        border: "#036",
        label: "#06c",
        background: "#cff"
      }
    };
  },
  methods: {
    onChange() {
      this.$refs.lf.value = this.value;
    }
  },
  components: {
    "yh-liquidfill": liquidfill
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scope>
</style>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值