Echarts饼状图修改图例legend⽂字颜⾊和字体⼤⼩
在默认的饼状图⾥⾯,图例legend颜⾊是⿊⾊的,有时候根据ui需要,根据不同的背景⾊,需要将图例⽂字调成⽩⾊或者其他颜⾊,那么,修改这些的还是⼀句话,修改某个属性即可。
主要改动的代码在这⾥:
legend: {
orient: 'vertical',
x: 'right',
y: 'bottom',
textStyle: { //图例⽂字的样式
textstyle
color: '#fff',
fontSize: 16
},
data: ['在线', '离线']
},
举⼀个实际的例⼦:
demo
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>五分钟上⼿之饼状图</title>
<!-- 引⼊ echarts.js -->
<script src="code.jquery/jquery-1.8.0.min.js"></script>
<script src="cdn.bootcss/echarts/4.2.1-rc1/echarts.min.js" type="text/javascript"></script>
</head>
<body>
<!-- 为ECharts准备⼀个具备⼤⼩(宽⾼)的Dom -->
<div id="main" ></div>
<script type="text/javascript">
$.ajax({
url: "data.json",
data: {},
type: 'GET',
success: function(data) {
/*    alert(JSON.stringify(data))*/
hrFun(data);
},
},
});
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.ElementById('main'));
function hrFun(param) {
myChart.setOption({
tooltip: {
trigger: 'item',
formatter: "{a} <br/>{b}: {c} ({d}%)"
},
legend: {
orient: 'vertical',
x: 'right',
y: 'bottom',
textStyle: { //图例⽂字的样式
color: '#0b2b5e',
fontSize: 12
},
data: ['在线', '离线']
},
series: [{
name: '访问来源',
type: 'pie',
radius: ['50%', '70%'],
avoidLabelOverlap: false,
label: {
normal: {
show: false,
position: 'center'
},
emphasis: {
show: true,
textStyle: {
fontSize: '30',
fontWeight: 'bold'
}
}
},
labelLine: {
normal: {
show: false
}
},
data: [{
value: param.peopleOutline,
name: '在线',
itemStyle: {
color: '#005eff'
}
},
{ value: param.peopleOnline, name: '离线', itemStyle: { color: '#ff9194' } },
]
}]
});
}
</script>
</body>
</html>
json
{"peopleTotal":15,"peopleOnline":4,"peopleOutline":12,"ranges":[]}
效果图如下所⽰:
可以看见,Echarts饼状图修改图例legend⽂字颜⾊和字体⼤⼩已经改变。
原⽂作者:祈澈姑娘 技术博客:
90后前端妹⼦,爱编程,爱运营,⽂艺与代码齐飞,魅⼒与智慧共存的程序媛⼀枚,欢迎关注【编程微刊】,回复【领取资源】,500G编程学习资源⼲货免费送。