百度echarts饼状legend显示值和百分比

1107 ℃

功能介绍:百度echarts做一个pie饼状,想要在legend名称后面加上当前的值和百分比,并且每个文字标签宽带一致(如右图),下面web建站小编给大家简单介绍一下实现代码!

实现代码如下:

//myData图表数据

legend: {
  bottom: '0',
  left: 'center',
  icon: "circle",
  itemHeight: 6,
  itemWidth: 6,
  formatter: function(name) {
    var total = 0
    var value
    for (var i = 0; i < myData.length; i++) {
      total += myData[i].value
      if (myData[i].name == name) {
        // 获取对应值
        value = myData[i].value
      }
    }
    let percent = Math.round((tarValue / total) * 100) + '%' // 获取百分百(根据需要在下面添加)
    var arr = ['{a|' + name + '}', '{b|' + value + '}']
    return arr.join('  ')
  },
  textStyle: {
    rich: {
      a: { //设置名称宽度
        width: 32
      },
      b: { //设置值的宽度
        width: 65,
      },
      c:{
	//.....一般值都可以设置
        //fontSize: 15,
        //color: '#c1c1c1'
      }
    }
  },
}

百度echarts雷达图radar根据分数点显示每个不同颜色

百度ECharts文档官网介绍

百度echarts柱状图设置不同颜色(每根柱子一种颜色)

百度echarts图表数据为空如何展示"暂无数据"

百度echarts柱状图/折线图x轴显示全部文本(太长自动换行)

标签: legend, 百度echarts, 饼状

上面是“百度echarts饼状legend显示值和百分比”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://m.ipkd.cn/webs_2889.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

在Java项目中如何更新MySQL数据库
如何找到网站首页被K屏蔽的原因?
vue项目报“vue/html-indent”等错误解决方法
el-select设置多选功能(multiple)不换行
php语法+mysql语法查询一个月时间内的数据