配置项如下
var dataAxis = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24'];
var data = [220, 182, 191, 234, 290, 330, 310, 123, 442, 321, 90, 149, 210, 122, 133, 334, 198, 123, 125, 220, 198, 123, 125, 220];
var yMax = 500;
var dataShadow = [];
for (var i = 0; i < data.length; i++) {
dataShadow.push(yMax);
}
option = {
backgroundColor:'white',
title: {
text: '使用高峰期',
subtext: ''
},
xAxis: {
data: dataAxis,
axisLabel: {
inside: true,
textStyle: {
color: '#fff'
}
},
axisTick: {
show: false
},
axisLine: {
show: false
},
z: 10
},
yAxis: {
axisLine: {
show: false
},
axisTick: {
show: false
},
axisLabel: {
textStyle: {
color: '#999'
}
}
},
dataZoom: [{
type: 'inside'
}],
series: [{ // For shadow
type: 'bar',
itemStyle: {
normal: {
color: 'rgba(0,0,0,0.05)'
}
},
barGap: '-100%',
barCategoryGap: '40%',
data: dataShadow,
animation: false
}, {
type: 'bar',
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(
0, 0, 0, 1, [{
offset: 0,
color: '#3DC7BE'
}, {
offset: 1,
color: '#2471A3'
}]
),
barBorderRadius: 30,
},
emphasis: {
color: new echarts.graphic.LinearGradient(
0, 0, 0, 1, [{
offset: 0,
color: '#2378f7'
}, {
offset: 0.7,
color: '#2378f7'
}, {
offset: 1,
color: '#83bff6'
}]
)
},
},
data: data
}],
label: {
normal: {
show: true,
position: 'top',
formatter: '{c}'
}
},
};
// Enable data zoom when user click bar.
var zoomSize = 6;
myChart.on('click', function(params) {
console.log(dataAxis[Math.max(params.dataIndex - zoomSize / 2, 0)]);
myChart.dispatchAction({
type: 'dataZoom',
startValue: dataAxis[Math.max(params.dataIndex - zoomSize / 2, 0)],
endValue: dataAxis[Math.min(params.dataIndex + zoomSize / 2, data.length - 1)]
});
});