let currentOption = 'pieOption';
const myChart = echarts.init(document.getElementById('main'));
const data = [
{ value: 335, name: '直接访问' },
{ value: 310, name: '邮件营销' },
{ value: 234, name: '联盟广告' },
{ value: 135, name: '视频广告' },
{ value: 1548, name: '搜索引擎' }
]
const option = {
series: [
{
type: 'pie',
data: data,
animationDurationUpdate: 1000,
universalTransition: true,
}
]
};
myChart.setOption(option);
const barOption = {
animationDurationUpdate: 1000,
xAxis: {
type: 'category',
axisLabel: {
rotate: 30
},
data: data.map(function (item) {
return item.name;
})
},
yAxis: {
type: 'value'
},
series: [
{
universalTransition: true,
type: 'bar',
data: [335, 310, 234, 135, 1548]
}
]
};
setInterval(function () {
currentOption = currentOption === 'pieOption' ? 'barOption' : 'pieOption';
(currentOption === 'pieOption') ? myChart.setOption(option, true) : myChart.setOption(barOption, true);
}, 2000);
标签:currentOption,const,name,示例,true,value,data
From: https://www.cnblogs.com/chen0509/p/18670618