Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

示例文件里,置空 series 无法清除数据 #10

Closed
benleilei opened this issue Jul 30, 2020 · 4 comments
Closed

示例文件里,置空 series 无法清除数据 #10

benleilei opened this issue Jul 30, 2020 · 4 comments

Comments

@benleilei
Copy link

benleilei commented Jul 30, 2020

在示例文件 index_zh_CN.html 末尾添加代码

setTimeout(function() {
    const opts = echarts.util.clone(option)
    opts.series = []
    chart.setOption(opts);
}, 3000)

无法清除地图上的点(echarts 官网中使用 bmap 是可以的)
只能通过

setTimeout(function() {
    const opts = echarts.util.clone(option)
    opts.series.forEach(s => {
        s.data = []
    })
    chart.setOption(opts);
}, 3000)

方式清除,这应该是一个 BUG

@plainheart
Copy link
Owner

@benleilei 感谢反馈,但我认为这个是 ECharts 的bug,默认如果不指定 notMergetrue,会采用合并的方式,所以 seriesdata 并不会被覆盖,也就是说只能通过遍历的方式把各个 seriesdata 置空。
这个问题会在接下来的 5.0 版本中得到优化。

@benleilei
Copy link
Author

可能我描述的有问题,问题不是在于 const opts = echarts.util.clone(option) 语句,即使写成 const opts = { xxxx, series: [] } 即我重写一个新的 JSON 对象,还是无法清除绘制到地图上的点。

setTimeout(function() {
    const opts = {
        amap: {
            viewMode: '3D',
            center: [108.39, 39.9],
            zoom: 4,
            resizeEnable: true,
            renderOnMoving: true,
            mapStyle:'amap://styles/dark'
        },
        tooltip : {
            trigger: 'item'
        },
        animation: true,
        series: []
    }
    chart.setOption(opts);
}, 3000);

我关注的点在于:series 被清空后,再次赋值,原先内容还是存在。
但是,使用 bmap 完全没有此问题

@plainheart
Copy link
Owner

需要手动将 series 中的 data 置空才可以,series: [] 不行,除非指定 notMergetrue
bmap没有此问题?能否提供一个例子?

@plainheart
Copy link
Owner

plainheart commented Jul 30, 2020

@benleilei 这是官网的bmap例子,如我上边所说的原因,也存在同样问题。
https://gallery.echartsjs.com/editor.html?c=xFt3nuTGd0&v=1
想要清空有两种办法,一个是你所说的遍历,另一个就是指定 notMergetrue,像这样:myChart.setOption(opts, true);
或者在 setOption 之前先调用 chart.clear()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants