多说无益,上码______
let chartDom = document.getElementById('myEchart4');
let myChart = echarts.init(chartDom);
let option;
option = {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
},
},
grid: {
left: '5%',
right: '5%',
bottom: '20%',
top: '10%',
containLabel: true
},
xAxis: {
type: 'value',
boundaryGap: [0, 0.01],
// splitLine:{show: false},
show: false
},
yAxis: {
// show: false,
type: 'category',
data: y,
axisTick: {
show: false
},
axisLine: {
show: false,
},
axisLabel: {
show: true,
left:10,
textStyle: {
color: '#fff',
fontSize:'11',
// align:'right',
},
formatter: function(value) {
// console.log(value)
let res = value;
if(res.length > 8) {
res = res.substring(0, 8) + "..";
}
return res;
},
},
},
series: [
{
barWidth: 15,
itemStyle: {
//通常情况下:
normal: {
barBorderRadius: 8,
//每个柱子的颜色即为colorList数组里的每一项,如果柱子数目多于colorList的长度,则柱子颜色循环使用该数组
color: function (params) {
let colorList = [
['rgb(14,102,179)', 'rgb(51,36,169)'],
['#0ED7EE', '#0076FF'],
['#A69CEF', '#6C19DA'],
['#73FFB2', '#00B92A'],
];
let index = params.dataIndex;
if (params.dataIndex >= colorList.length) {
index = params.dataIndex - colorList.length;
}
return new echarts.graphic.LinearGradient(0, 0, 1, 0,
[{
offset: 0,
color: colorList[index][0]
},
{
offset: 1,
color: colorList[index][1]
}
]);
}
},
},
// name: '2011年',
type: 'bar',
width: '15',
data: x
},
]
};
myChart.setOption(option,true);