apache / echarts

Apache ECharts is a powerful, interactive charting and data visualization library for browser
https://echarts.apache.org
Apache License 2.0
60.59k stars 19.62k forks source link

echarts能提供仅清除series属性的接口吗 #15179

Closed Sakura-gh closed 3 years ago

Sakura-gh commented 3 years ago

What problem does this feature solve?

使用this.chartInstance.clear()或this.chartInstance.setOption(..., true)都会把原先所有的内容给清空,尤其是在使用百度地图时,由于bmap属性被清除,导致所有自定义样式也会一同消失。如果使用上述两种方法,需要重新加载过多的资源,导致刷新卡顿。目前的需求是仅仅清空原option中的series属性,而不用清除其他属性导致重复加载。

注:我尝试过replaceMerge方法,在没有设置series属性id的情况下,replaceMerge似乎并不能完整地删除原有的series:

console.log(this.chartInstance.getOption())
this.chartInstance.setOption(dataOption, {replaceMerge: 'series'})
console.log(this.chartInstance.getOption())

console输出: 原先的series:

series: Array(2)
0: {name: "飞线", type: "lines", coordinateSystem: "bmap", symbol: Array(2), effect: {…}, …}
1: {name: "终点", type: "effectScatter", coordinateSystem: "bmap", rippleEffect: {…}, symbolSize: 10, …}

setOption之后的series:

series: Array(2)
0: {type: "effectScatter", coordinateSystem: "bmap", animation: true, symbol: "circle", symbolSize: 15, …}
1: {name: "终点", type: "effectScatter", coordinateSystem: "bmap", rippleEffect: {…}, symbolSize: 10, …}

新的series只包含0: {type: "effectScatter", coordinateSystem: "bmap", animation: true, symbol: "circle", symbolSize: 15, …},显然这个结果是删除了原series中的0: {name: "飞线", type: "lines", coordinateSystem: "bmap", symbol: Array(2), effect: {…}, …},却保留了不应该保留的1: {name: "终点", type: "effectScatter", coordinateSystem: "bmap", rippleEffect: {…}, symbolSize: 10, …}

What does the proposed API look like?

chartInstance.clearSeries()

echarts-bot[bot] commented 3 years ago

Hi! We've received your issue and please be patient to get responded. 🎉 The average response time is expected to be within one day for weekdays.

In the meanwhile, please make sure that it contains a minimum reproducible demo and necessary images to illustrate. Otherwise, our committers will ask you to do so.

A minimum reproducible demo should contain as little data and components as possible but can still illustrate your problem. This is the best way for us to reproduce it and solve the problem faster.

You may also check out the API and chart option to get the answer.

If you don't get helped for a long time (over a week) or have an urgent question to ask, you may also send an email to dev@echarts.apache.org. Please attach the issue link if it's a technical question.

If you are interested in the project, you may also subscribe our mailing list.

Have a nice day! 🍵

echarts-bot[bot] commented 3 years ago

@Sakura-gh It seems you are not using English, I've helped translate the content automatically. To make your issue understood by more people, we'd like to suggest using English next time. 🤗

TRANSLATED
**TITLE** Can echarts provide an interface that clears only the series property? **BODY** ### What problem does this feature solve? Using this.chartInstance.clear() or this.chartInstance.setOption(..., true) will clear all the original content, especially when using Baidu map, because the bmap attribute is cleared, all custom styles are also Will disappear together. If you use the above two methods, you need to reload too many resources, resulting in refresh freeze. The current requirement is to only clear the series attributes in the original option, without clearing other attributes to cause repeated loading. ### What does the proposed API look like? chartInstance.clearSeries()
100pah commented 3 years ago

@Sakura-gh echarts 版本是多少呢?

以及, setOption(dataOption, ...)dataOption 是什么内容。

Sakura-gh commented 3 years ago

@Sakura-gh echarts 版本是多少呢?

以及, setOption(dataOption, ...)dataOption 是什么内容。

我发现自己使用的是echarts4.9.0版本,好像并不支持replaceMerge参数,以上的情况应该是直接发生了merge和替换

100pah commented 3 years ago

v5 后支持 replaceMerge ,能只清除 series 。