遇到 options 中的 series 值改变,但是页面没有重新绘制,导致页面没有变化
option = {
title: {
text: 'Stacked Line'
},
tooltip: {
trigger: 'axis'
},
legend: {
data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [
{
name: 'Email',
type: 'line',
stack: 'Total',
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: 'Union Ads',
type: 'line',
stack: 'Total',
data: [220, 182, 191, 234, 290, 330, 310]
}
]
};
function run() {
option.series = [
{
name: 'Email',
type: 'line',
stack: 'Total',
data: [120, 132, 101, 134, 90, 230, 210]
}
];
myChart.setOption(option);
}
setTimeout(function() {
run()
}, 1000);
按照道理这样就是重新绘制,结果就是实现不了,找了好久发现问题了
myChart.setOption(option, true); // 第二个参数为true,表示不合并,直接覆盖
function run() {
option.series = [
{
name: 'Email',
type: 'line',
stack: 'Total',
data: [120, 132, 101, 134, 90, 230, 210]
}
];
myChart.setOption(option, true); // 第二个参数为true,表示不合并,直接覆盖
}
如果对您有帮助,请随意随喜🙏🏻