Angular-创建一个带有主内容和副内容的饼状图表

最近遇到一个需求,大概是这个样子在这里插入图片描述

本来想用D3js去画,后来发现这个主要得问题在于饼状图里面的两个label是不同格式,有一个主内容和副内容,查了查也没有找到合适的方法(对不起,其实就是没画明白)。

然后找了找其他插件,发现echart这个插件太好用了。他的核心也是d3,但是封装的很好,稍微改改就可以达到效果。
点击可以进入官网echarts

1.安echarts插件

这个自行百度吧 ?

2.给图表一个空间(view)

 <div echarts [options]="pieoption" [loading]="showloading" class="demo-chart"></div>

[options]是图标的一个标志位,我们需要在ts里写下绘制图表的逻辑
[loading]给他一个延迟加载的动画效果

3.绘制图表(controller)

延迟动画

constructor() {
    setTimeout(() => {
      this.showloading = false;
    }, 3000);
    this.news = MOCKNEWS;
  }

绘制图表

 this.pieoption = {
      color: ['#E6E7E9', '#E6E7E9'],
      tooltip: {
        show: false//display prompt
      },
      series: [{
        name: '您所选取功能所占总金额得百分比',
        type: 'liquidFill', 
        radius: ['60%', '70%'],//control pie width
        label: {
          normal: {
            position: 'center'
          }
        },
        hoverAnimation: true,
        data: [{
          value: this.realTotal,
          name: '',
          itemStyle: {
            normal: {
              color: {
                colorStops: [{
                  offset: 0,
                  color: '#367bec' // 0% color
                }, {
                  offset: 1,
                  color: '#28D2E3' // 100% color
                }]
              },
              borderWidth: 0,
              label: {
                show: true
              },
              labelLine: {
                show: false
              }
            }
          },
          label: {
            normal: {
              formatter: '{d}%',
              textStyle: {
                color: '#000',
                fontSize: 120,
                fontWeight: 'bold'
              }
            }
          },
        }, {
            value: this.unlessTotal,
            name: '',
            itemStyle: {
              normal: {
                color: {
                  colorStops: [{
                    offset: 0,
                    color: '#E6E7E9' // 0% color
                  }, {
                    offset: 1,
                      color: '#E6E7E9' // 100% color
                  }]
                },
                borderWidth: 0,
                label: {
                  show: true
                },
                labelLine: {
                  show: false
                }
              }
            },
          label: {
            normal: {
              formatter: '\n\n\n您所选取功能所占总金额得百分比\nThe percentafe of the total amount of\n functional requirements\n that you select',
              textStyle: {
                color: '#000',
                fontSize: 25
              }
            }
          }
        }]
      }]
    };
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值