给柱状体添加渐变色的效果如下:
代码如下:
option = {
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [
{
data: [120, 200, 150, 80, 70, 110, 130],
type: 'bar',
itemStyle: {
color: {
type: 'linear',
x: 0,
y: 1,
x2: 0,
y2: 0,
colorStops: [
{
offset: 0,
color: '#3484ff' // 0% 处的颜色
},
{
offset: 0.5,
color: '#536AF9' // 50% 处的颜色
},
{
offset: 1,
color: '#6F5DFE' // 100% 处的颜色
}
]
}
},
}
]
};
备注:可以在echarts官网示例中运行:https://echarts.apache.org/examples/zh/editor.html?c=bar-simple