配置效果
配置每个柱子不同颜色的代码
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0, color: 'red'
}, {
offset: 1, color: 'blue'
}], false)
}
}
完整代码
var option = {
title: {
text: '碳排放量(tCO2e)',
textStyle: {
color: '#fff',
fontSize: 14,
fontWeight: 400,
fontFamily: 'Microsoft YaHei'
}
},
tooltip: {},
xAxis: {
data: ['常减压', '2#常', '催化', '重加'],
axisLine: {
show: true,
lineStyle: {
color: "#CBEDFF"
},
},
axisTick: {
show: false
},
},
yAxis: {
type: 'value',
axisLine: {
show: false,
lineStyle: {
color: "#CBEDFF"
},
},
axisTick: {
show: false
},
splitNumber: 10,
splitLine: {
show: true,
lineStyle: {
color: "#006691"
}
},
},
series: [{
name: '碳排放量',
type: 'bar',
data: [3500, 2000, 1800, 1600],
backgroundStyle: {
color: '#00FCFF'
},
barWidth: 21,
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0, color: 'red'
}, {
offset: 1, color: 'blue'
}], false)
}
}
}]
};
配置每个柱子的渐变颜色
itemStyle: {
normal: {
color: function (params) {
console.log(params);
var colorList = [
['#00FCFF', '#008297'],
['#0091FF', '#005EA4'],
['#901698', '#F157EE'],
['#40FBCB', '#009871']
];
var colorItem = colorList[params.dataIndex];
return new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,
color: colorItem[0]
},
{
offset: 1,
color: colorItem[1]
}
], false);
}
}
},
完整代码
var option = {
title: {
text: '碳排放量(tCO2e)',
textStyle: {
color: '#fff',
fontSize: 14,
fontWeight: 400,
fontFamily: 'Microsoft YaHei'
}
},
tooltip: {},
xAxis: {
data: ['常减压', '2#常', '催化', '重加'],
axisLine: {
show: true,
lineStyle: {
color: "#CBEDFF"
},
},
axisTick: {
show: false
},
},
yAxis: {
type: 'value',
axisLine: {
show: false,
lineStyle: {
color: "#CBEDFF"
},
},
axisTick: {
show: false
},
splitNumber: 10,
splitLine: {
show: true,
lineStyle: {
color: "#006691"
}
},
},
series: [{
name: '碳排放量',
type: 'bar',
data: [3500, 2000, 1800, 1600],
backgroundStyle: {
color: '#00FCFF'
},
barWidth: 21,
itemStyle: {
normal: {
color: function (params) {
console.log(params);
var colorList = [
['#00FCFF', '#008297'],
['#0091FF', '#005EA4'],
['#901698', '#F157EE'],
['#40FBCB', '#009871']
];
var colorItem = colorList[params.dataIndex];
return new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,
color: colorItem[0]
},
{
offset: 1,
color: colorItem[1]
}
], false);
}
}
},
}]
};
|