
功能介绍:百度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柱状图/折线图x轴显示全部文本(太长自动换行)
上面是“百度echarts饼状legend显示值和百分比”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_2889.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

js如何将数据转为exe文件
妙办AI:一键生成各种思维导图,包括读书笔记/职业规划/旅游攻略/会议纪要等
奇游手游加速器