v-charst环图默认显示数据

封装组件只能用ref做class标识,原生的echars是用id做标识,设置默认选中高亮部分用dispatchAction方法

<template>
  <div>
    <ve-ring :settings="chartSettings3" :extend="percentExtend"  height="280px" ref="chart_ring" :data="chartData3"></ve-ring>

  </div>

</template>

<script>
  export default {
    name: 'pie',

    props: {
      data: Object

    },
    data () {

      this.dataZoom = [
        {
          type: 'slider',
          start: 0,
          end: 20
        }
      ]

      this.chartSettings3 = {
        radius: 70,
        offsetY: 110,
        dataType: function (v) {
          return v + ' 台'
        }
      }

      return {
        stadata: this.data,
        grid2: {
          // 调整位置
          top: 50,
          // 调整大小啥的
          height: 200
        },
        grid:{
          // 调整位置
          top: 10,
          //调整大小啥的
          height: 240
        },

        percentExtend: {
          // series: {
          //   symbolSize: 10,
          //   label: {
          //     normal: {
          //       show: true,
          //       formatter: '{b}: {d}%',
          //       // position: 'center'       //center表示文本显示位置为内部
          //     }
          //   },
          //   labelLine: {    //引导线设置
          //     normal: {
          //       show: false,   //引导线显示
          //     }
          //   }
          // },
          series:  {

          type: 'pie',
          radius: ['50%', '70%'],
          avoidLabelOverlap: false,
          label: {
          normal: {
            show: false,
              position: 'center',
                  formatter: '{b}: {d}%',
            // formatter: function(data){ // 设置圆饼图中间文字排版
            //   return data.value+"\n"+"用户数"
            // }
          },
          emphasis: {
            show: true,
              textStyle: {
              fontSize: '20',
                fontWeight: 'bold'
            }
          }
        },
        labelLine: {
          normal: {
            show: false
          }
        },
      },

          legend: {
            bottom: 5,

          },


        },

        // 饼图状态统计
        chartData3: {
          columns: [ 'type', 'num' ],
          rows: [
            { 'type': '在线设备', 'num': this.data.onlineCount },

            { 'type': '离线设备', 'num': this.data.offlineCount }
          ]
        },
        created(){

        },
        methods: {

        },

      }

    },

    mounted () {
      this.$nextTick(() => {
        var chart = this.$refs['chart_ring'].echarts;
        setTimeout(function () {
          chart.dispatchAction({
            type: 'highlight',
            // 可选,系列 index,可以是一个数组指定多个系列
            seriesIndex: 0,
            dataIndex: 0
          });
          chart.selected = 0;//记录选中的项目
        }, 0);
        //鼠标放置时高亮,移开后取消高亮
        chart.on('mouseover', function (params) {
          var options = this.getOption();
          var data = options.series[params.seriesIndex].data;
          for (var i = 0; i < data.length; i++) {
            if (i !== params.dataIndex) {
              this.dispatchAction({
                type: 'downplay',
                dataIndex: i
              });
            }
          }
        });
        //鼠标单击时选中
        chart.on('click', function (params) {
          chart.dispatchAction({
            type: 'highlight',
            // 可选,系列 index,可以是一个数组指定多个系列
            seriesIndex: 0,
            dataIndex: params.dataIndex
          });
          this.selected = params.dataIndex;//选中的项目
        });
        //当鼠标移出时恢复默认或者单击选中的项目
        chart.on('mouseout', function (params) {
          this.dispatchAction({
            type: 'highlight',
            dataIndex: this.selected
          });
        });
      });
    }
  }
</script>

<style scoped>

</style>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值