【echart 图表绘制,圆环图,自定义legend】

demo记录
增加中间文字显示,自定义legend

var seriesdata = [
  { value: 110, name: '语文成绩' },
  { value: 5, name: '数学' },
  { value: 140.5, name: '英语成绩' }
];
option = {
  tooltip: {
    trigger: 'item'
  },
  color:['#2A73FE','#5AC581','#4CBDF3','#6C7E9E',],
  title: [
    {
      text: `23043`,
      subtext: '今日识别总数',
      left: '29%',
      top: '45%',
      textAlign: 'center',
      textStyle: {
        color: '#000',
        fontWeight: 'bold',
        fontSize: 33
      },
      subtextStyle: {
        color: 'rgba(34,34,34,0.75)',
        fontWeight: 'normal',
        fontSize: 15
      }
    }
  ],
  // graphic: {
  //   type: 'text',
  //   left: 'center', // 相对位置,居中
  //   top: 'center', // 相对位置,居中
  //   style: {
  //     text: 'Your Text', // 中间显示的文本
  //     textAlign: 'center',
  //     fill: '#000', // 文字的颜色
  //     fontSize: 30
  //   }
  // },
  legend: {
    orient: 'vertical',
    icon: 'circle', // 设置图例为圆点
    // left: 'right',
    // right: 30,
    top: '40%',
    left: '60%',
    bottom: 20,
    type: 'scroll',

    textStyle: {
      // 文字的样式
      fontSize: 24, // 可控制每个legend项的间距
      color: '#828282',
      rich: {
        // 通过富文本rich给每个项设置样式,下面的oneone、twotwo、threethree可以理解为"每一列"的样式
        oneone: {
          // 设置文字、数学、英语这一列的样式
          width: 50,
          color: '#000000',
          fontSize: 13,
          fontWeight: 'bolder'
        },
        twotwo: {
          // 设置10分、20分、30分这一列的样式
          width: 35,
          color: '#333',
          fontSize: 13
        },
        threethree: {
          // 设置百分比这一列的样式
          width: 20,
          color: '#333',
          fontSize: 13
        }
      }
    },
    formatter: (name) => {
      // formatter格式化函数动态呈现数据
      console.log(name);
      var total = 0; // 用于计算总数
      var target; // 遍历拿到数据
      for (var i = 0; i < seriesdata.length; i++) {
        total += seriesdata[i].value;
        if (seriesdata[i].name == name) {
          target = seriesdata[i].value;
        }
      }
      var v = ((target / total) * 100).toFixed(2);
      return `{oneone|${name}}   {twotwo|${target}}   {threethree|${v}%}`;
      //     富文本第一列样式应用    富文本第二列样式应用      富文本第三列样式应用
    }
  },
  series: {
    type: 'pie',
    radius: ['40%', '53%'],
    // center: ['40%', '50%'],
    center: ['30%', '50%'],
    avoidLabelOverlap: true,

    label: {
      show: false,
      position: 'center',
      normal: {
        show: false // 不显示饼图上的文本标签
      }
    },
    itemStyle: {
      //添加间隙
      borderRadius: 4,
      borderColor: '#fff',
      borderWidth: 3
    },
    emphasis: {
      label: {
        show: true,
        fontSize: 20,
        fontWeight: 'bold'
      }
    },
    labelLine: {
      show: false
    },
    data: seriesdata
  }
};

对你有用记得点个赞
运行结果:
在这里插入图片描述

ECharts是一款功能强大的可视化图表库,可以用于绘制各种图表,包括自定义形状的圆形。 要绘制自定义圆形,可以使用ECharts中的自定义系列来实现。自定义系列允许用户在图表绘制自己定义的形,包括各种形状的圆形。 首先,需要使用ECharts自定义系列功能来定义一个新的系列类型,可以将其命名为"customCircle"。然后,需要为这个系列类型指定对应的系列配置项,包括颜色、圆形半径等信息。 接下来,在数据中添加要绘制的圆形的位置和大小信息。可以通过设置一个包含圆形坐标和半径的数据数组来实现。例如: data: [ {center: [100, 100], radius: 50}, {center: [200, 200], radius: 80}, ... ] 最后,在ECharts的option配置中,将定义的自定义系列类型"customCircle"添加到series数组中,同时将数据设置为刚刚定义的数据数组。可以通过设置symbol为"circle"来表示要绘制圆形。 完整的代码示例如下: option: { series: [{ type: 'custom', name: 'customCircle', renderItem: function(params, api) { var coord = api.coord(params.value.center); var radius = params.value.radius; return { type: 'circle', shape: { cx: coord[0], cy: coord[1], r: radius }, style: api.style() }; }, data: [ {center: [100, 100], radius: 50}, {center: [200, 200], radius: 80}, ... ] }] } 以上代码中,renderItem函数用于渲染自定义的圆形形,并通过api.style()来获取样式信息。最后,将配置项添加到对应的option中即可。 利用ECharts自定义系列功能,我们可以轻松地绘制出各种自定义形状的圆形形,实现图表的个性化展示。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值