echarts 折線圖自定義顏色與修改legend顏色

 

option4 = {
title : {
text: '',
subtext: ''
},
color:['#2db7f5','#ff6600','#808bc6'],      //關鍵加上這句話,legend的顏色和折線的自定義顏色就一致了
legend: {
icon: 'rectangle',
data: ['total', 'dfs_used','non_dfs_used'],
right: '4%',
textStyle: {
fontSize: 12,
color: '#666'
}
},
/*grid:{y:15},*/
tooltip : {
trigger: 'axis'
},
calculable : true,
yAxis : [
{
type : 'value',
splitLine:{show: false},//去除網格線
//boundaryGap : [0, 0.1],
axisLabel: {
show: true,
textStyle: {
color:'#666' //這裏用參數代替了
}
},
}
],
xAxis : [
{
type : 'category',
splitLine:{show: false},//去除網格線
data : ['5','10','15','20','25','30','35','40','45'],
axisLabel: {
show: true,
textStyle: {
color:'#666' //這裏用參數代替了
}
},
}
],
series : [
{
name:'total',
type:'line',
symbol:'none', //這句就是去掉點的
smooth:true,
barWidth:'37',
data:[43, 48, 36, 32, 46, 32,30, 40, 29],
//symbol:'none',
//smooth:true,
itemStyle: {
normal: {
areaStyle: {type: 'default',color:'#d5f0fd'},
lineStyle:{color:'#2db7f5'}
}
},
},
{
name:'dfs_used',
type:'line',
symbol:'none', //這句就是去掉點的
smooth:true,
barWidth:'37',
data:[28, 32, 30, 52, 56, 22,20, 25, 20],
itemStyle: {
normal: {
areaStyle: {type: 'default',color:'#fff5e6'},
lineStyle:{color:'#ff6600'}
}
}
},
{
name:'non_dfs_used',
type:'line',
symbol:'none', //這句就是去掉點的
smooth:true,
barWidth:'37',
data:[20, 12, 20, 32, 46, 12,10, 15, 10],
itemStyle: {
normal: {
areaStyle: {type: 'default',color:'#dcdfee'},
lineStyle:{color:'#808bc6'}
}
}
}
]
};spa