echarts柱状图不同的柱⼦循环显⽰不同的渐变颜⾊
getBarECharts (xdata, ydata) {
let medicalCare = echarts.ElementById('medicalCare'))
let option = {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#6a7985'
}
}
},
grid: {
top: 30,
bottom: 30
},
textStyle: {
fontSize: 16,
color: '#fff'
},
xAxis: {
type: 'category',
axisLine: {
lineStyle: {
color: '#274365'
}
},
data: xdata,
},
yAxis: {
type: 'value',
axisLine: {
show: fal,
lineStyle: {}
},
splitLine: {
show: true,
lineStyle: {
type: 'dashed',
color: '#274365'
}
}
},
ries: [
{ // For shadow
type: 'bar',
itemStyle: {
normal: {color: 'rgba(20,73,152,0.6)'}
},
barGap: '-100%',
barCategoryGap: '40%',
animation: fal
},
{
data: ydata,
type: 'bar',
itemStyle: {
normal: {
color: function (params) {
var colorList = [
['#569cea', '#633fdd'],
['#266fe6', '#d2ad21'],
['#266fe6', '#d2ad21'],
['#256ee7', '#d24047']
]
var index = params.dataIndex
if (params.dataIndex >= colorList.length) {
index = params.dataIndex - colorList.length
}
// 配置⽂件中的:0,0,0,1的意思是颜⾊竖向排列,0,0,1,0的意思是颜⾊横向渲染,1,0,0,0 横向相反渲染,0,1,0,0 竖向相反渲染 return aphic.LinearGradient(0, 1, 0, 0,
[
{
offt: 0,
color: colorList[index][0] // 0% 处的颜⾊
},
{
offt: 1,
color: colorList[index][1] // 100% 处的颜⾊
}
])
}
}
},
barWidth: 15
}
]
}
medicalCare.tOption(option)
}