echarts圆环制作

<div id="chart" ref="chart":style="{width: '100%', height: '300px'}"></div>
import echarts from 'echarts'
mounted () {
  this.initChart();

  this.$nextTick(() => {     //初始化
    this.initChart();
    this.getChartData();
    window.addEventListener("resize", () => {
      this.resize();           //监听屏幕大小,来刷新画布
    });
  });
},
methods: {
  //查询图表数据  动态的改变数据
  getChartData() {
    this.chart.hideLoading();
  },
  // echarts表格
  initChart() {
    let option = {
      title: {
      },
      tooltip: {
        trigger: 'item',
        formatter: "{a} <br/>{b}: {c} ({d}%)"
      },
      //颜色
      color: ['#FFAF5F','#58E88A','#FF8A8F','#267AFE'],

      //圆环右上方的提示
      legend: {
        orient: 'vertical',
        x: '55%',  // x轴位置
        y: '8%',   // y轴位置
        data:['贷款xx万/xx月','利息xx元(xx%/月)','月利息xx元','费用无']
      },
      // 圆环内name
      graphic: [{
        type: 'text',
        left: '9.5%',
        top: '20%',
        fontSize: 12,
        style: {
          text: '总利息:1.2万元',
          fill: '#212937'
        }
      },{
        type: 'text',
        left: '11%',
        top: '28%',
        fontSize: 12,
        style: {
          text: '月供:1.2万元',
          fill: '#212937'
        }
      }],
      series: [
        {
          name:'访问来源',
          type:'pie',
          radius: ['30%', '40%'],
          center: ['20%', '25%'],
          avoidLabelOverlap: false,
          label: {
            normal: {
              show: false,
              position: 'left',
            },
            //点击圆环有提示
            // emphasis: {
            //   show: true,
            //   textStyle: {
            //     fontSize: '14',
            //     fontWeight: '500'
            //   }
            // }
          },
          labelLine: {
            normal: {
              show: false
            }
          },
          data:[
            {value:335, name:'贷款xx万/xx月'},
            {value:310, name:'利息xx元(xx%/月)'},
            {value:234, name:'月利息xx元'},
            {value:135, name:'费用无'},
          ]
        }
      ]
    };

    this.chart = echarts.init(this.$refs.chart);   //定义
    this.chart.showLoading();  //等待的显示
    this.chart.setOption(option);  //展示
    this.chart.resize(); //刷新画布
  },
  resize() {
    if (this.chart) {
      this.chart.resize();
    }
  },
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值