option = {
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri']
},
yAxis: {
type: 'value'
},
series: [
{
data: [320, 200, 150, 80, 60],
name: 'sales',
type: 'pictorialBar',
legendHoverLink: true,
label: {
show: false,
position: 'insideTop',
rotate: 0,
color: '#eee'
},
itemStyle: {
normal: {
color: (params) => {
// colorList是每根柱子的颜色,一组是一个渐变
var colorList = [
['#62C467', '#278D65'],
['#FF5B7A', '#BC3535'],
['#FFF600', '#D69105'],
['#FFB400', '#F66800'],
['#00CCFF', '#2A54B4'],
['#F75271', '#754ABF']
];
var index = params.dataIndex;
// 柱子个数超过colorList设置的个数,循环使用
if (index >= colorList.length) {
index = index - colorList.length;
}
// 这里的this.$echarts是项目中的echarts示例,改成对应的名字就好
return new this.echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: colorList[index][0]
},
{
offset: 1,
color: colorList[index][1]
}
]);
},
label: {
show: true, //开启显示
position: 'top', //在上方显示
textStyle: {
//数值样式
// color: 'black',
//fontSize: 16
}
}
}
},
emphasis: {
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#2378f7' },
{ offset: 0.7, color: '#2378f7' },
{ offset: 1, color: '#83bff6' }
])
}
},
barWidth: '80',
barCategoryGap: '5%',
symbol: 'path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z'
}
]
};