echarts 柱状图自动轮播
时间: 2023-11-12 10:59:37 浏览: 357
您可以使用 echarts 的 dataZoom 组件来实现柱状图的自动轮播。具体步骤如下:
1. 在 option 中添加 dataZoom 组件,并设置其 type 为 slider。
2. 设置 dataZoom 的 start 和 end 属性,表示初始显示的数据范围。
3. 设置 dataZoom 的 handleIcon 和 handleSize 属性,用于设置滑块的样式和大小。
4. 设置 dataZoom 的 realtime 属性为 true,表示开启实时更新。
5. 使用 setInterval 函数定时更新 dataZoom 的 start 和 end 属性,实现自动轮播。
以下是一个示例代码:
```
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'
}],
dataZoom: [{
type: 'slider',
start: 0,
end: 50,
handleIcon: 'path://M512 64c-247.424 0-448 200.576-448 448s200.576 448 448 448 448-200.576 448-448-200.576-448-448-448z m0 832c-194.08 0-352-157.92-352-352s157.92-352 352-352 352 157.92 352 352-157.92 352-352 352z',
handleSize: '80%'
}],
animationDuration: 2000,
animationEasing: 'cubicInOut',
animationDelay: function (idx) {
return idx * 100;
}
};
// 自动轮播
var start = 0;
var end = 50;
setInterval(function () {
start += 10;
end += 10;
if (end > 100) {
start = 0;
end = 50;
}
myChart.dispatchAction({
type: 'dataZoom',
start: start,
end: end
});
}, 2000);
```
阅读全文
相关推荐















