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

API: echarts.clear() 该方法清空当前实例。使用该方法后调用 getOption 方法返回并不是空对象 #7959

Closed
admin-style opened this issue Mar 16, 2018 · 13 comments
Assignees
Labels
doc Document or Website related issues.

Comments

@admin-style
Copy link

echartsAPI接口 echartsInstance 中的clear() 该方法作用是清空当前实例。但是使用该方法后调用 getOption 方法返回并不是空对象

One-line summary [问题简述]

例如:
var echartsLineOne = echarts.init(document.getElementById('echartsLineOne'));
echartsLineOne.clear();
console.log(echartsLineOne.getOption()); // 此处获取的对象不是空对象

Version & Environment [版本及环境]

  • ECharts version [ECharts 版本]: 版本V3
  • Browser version [浏览器类型和版本]: chrome 64
  • OS Version [操作系统类型和版本]:

Expected behaviour [期望结果]

修改接口

ECharts option [ECharts配置项]

option = {

}

Other comments [其他信息]

@Ovilia
Copy link
Contributor

Ovilia commented Mar 19, 2018

请调用 chart.dispose() 清空

@admin-style
Copy link
Author

dispose 不是注销实例么

@admin-style
Copy link
Author

而且调用该方法后,去调用实例会报错

@Ovilia
Copy link
Contributor

Ovilia commented Mar 19, 2018

你不是要注销实例?那“清空当前实例”是什么意思?

@admin-style
Copy link
Author

admin-style commented Mar 20, 2018

不是注销实例,是需要去清空当前的option值。官网不是有提供一个clear的接口么,但是这个接口和文档http://echarts.baidu.com/api.html#echartsInstance.clear
所描述的不一样,clear()函数使用后getOption()竟然不是返回空对象。

@manglobe
Copy link

echartsProto.clear = function () {
  this.setOption({
    series: []
  }, true);
};

clear只清除了series ,跟文档有出入

@Ovilia Ovilia added the pending We are not sure about whether this is a bug/new feature. label Aug 7, 2018
@visiky
Copy link

visiky commented Dec 5, 2019

请问这个问题什么时候 解决呢

@pissang pissang added enhancement difficulty: easy Issues that can be fixed more easily than the average. and removed pending We are not sure about whether this is a bug/new feature. labels Dec 10, 2019
@echarts-bot
Copy link

echarts-bot bot commented Dec 10, 2019

This issue is labeled with difficulty: easy.
@admin-style Would you like to debug it by yourself? This is a quicker way to get your problem fixed. Or you may wait for the community to fix.

Please have a look at How to debug ECharts if you'd like to give a try. 🤓

@pissang pissang added this to the 4.8.0 milestone Dec 10, 2019
@dongsuo
Copy link

dongsuo commented Dec 13, 2019

嗯,我看了下 issue 里提到 clear 方法实际上是调用了setOption({series:[]}),我以为改成setOption({}) 就可以解决,结果发现 setOption 方法好像也不符合期望

myChart.setOption({}, true)
console.log(myChart.getOption())  //  打印出来的 option 并不为空

@Ovilia
Copy link
Contributor

Ovilia commented Dec 13, 2019

我的理解是,myChart.setOption({}, true) 会和默认的配置项合并,所以 myChart.getOption() 是不会返回空的。我认为应该是 clear() 方法里 myChart.setOption({}, true) 之后,记录一下清空状态,然后 getOption 判断清空后返回 {}@100pah 是这样吗?

@dongsuo
Copy link

dongsuo commented Dec 13, 2019

我的理解是,myChart.setOption({}, true) 会和默认的配置项合并,所以 myChart.getOption() 是不会返回空的。我认为应该是 clear() 方法里 myChart.setOption({}, true) 之后,记录一下清空状态,然后 getOption 判断清空后返回 {}@100pah 是这样吗?

验证了一下,好像是这样的

@100pah
Copy link
Member

100pah commented Dec 13, 2019

我觉得,是不是应该修改一下文档。
按照定义来说,getOption 总应该返回当前 option 的状态。
而 option 中实际永远不可能是 “空对象” 的状态。
所以应该把文档中,返回空对象这个说法,去掉?

@deqingli
Copy link
Member

deqingli commented Jan 14, 2020

文档已修改,谢谢各位的建议。

@deqingli deqingli self-assigned this Jan 14, 2020
@Ovilia Ovilia added doc Document or Website related issues. and removed difficulty: easy Issues that can be fixed more easily than the average. enhancement labels Feb 12, 2020
@Ovilia Ovilia removed this from the 4.8.0 milestone Mar 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Document or Website related issues.
Projects
None yet
Development

No branches or pull requests

8 participants