apache / echarts

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

[Question] 如何正确的使用切换主题功能? #20478

Closed wccd closed 1 week ago

wccd commented 2 weeks ago

What problem does this feature solve?

let option = this.chart.getOption(); echarts.dispose(this.chart); this.chart = echarts.init(dom, "themeName"); this.chart.setOption(option));

当前是这样设置主题的,会导致第二次调用时option已经是前一个主题内容,从而覆盖第二次使用的主题。不确定是否我的使用方式有误。

What does the proposed API look like?

期望有一个更便捷的切换主题内置方法

echarts-bot[bot] commented 2 weeks ago

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

TRANSLATED
**TITLE** [Question] How to use the switch theme function correctly?
helgasoft commented 2 weeks ago

Please search issues first, like that. Duplicate of #18198, #18540

wccd commented 2 weeks ago

Please search issues first, like that. Duplicate of #18198, #18540 I want to know how to switch themes while keeping the option. echart will pollute the options after toggle theme. At this time, the options obtained by using the getOption Api are unreliable.

Ovilia commented 2 weeks ago

I would recommend:

const option = {...};
chart.setOption(option);

// reset theme when necessary
chart = echarts.init(dom, 'theme-name');
chart.setOption(option, true); // Use notMerge: true to reset all options before.
wccd commented 2 weeks ago

I would recommend:

const option = {...};
chart.setOption(option);

// reset theme when necessary
chart = echarts.init(dom, 'theme-name');
chart.setOption(option, true); // Use notMerge: true to reset all options before.

For some reason, I need to record echart's options for the next render. Just like JSON.string(echart.getOption()), But this will carry theme data,So I had to find a way to remove the theme data.

Ovilia commented 2 weeks ago

JSON.string(echart.getOption()) is Okay but the returned value also contains default values from ECharts.