Skip to content

feat: dynamically update the theme #841

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

Merged
merged 5 commits into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Drop `<script>` inside your HTML file and access the component via `window.VueEC

```html
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/echarts@5.5.1"></script>
<script src="https://cdn.jsdelivr.net/npm/echarts@6.0.0-beta.1"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
```

Expand Down Expand Up @@ -331,6 +331,12 @@ export default {
- `clear` [](https://echarts.apache.org/en/api.html#echartsInstance.clear)
- `dispose` [](https://echarts.apache.org/en/api.html#echartsInstance.dispose)

> [!NOTE]
> The following ECharts instance methods aren't exposed because their functionality is already provided by component [props](#props):
>
> - [`showLoading`](https://echarts.apache.org/en/api.html#echartsInstance.showLoading) / [`hideLoading`](https://echarts.apache.org/en/api.html#echartsInstance.hideLoading): use the `loading` and `loading-options` props instead.
> - `setTheme`: use the `theme` prop instead.
### Static Methods

Static methods can be accessed from [`echarts` itself](https://echarts.apache.org/en/api.html#echarts).
Expand Down
8 changes: 7 additions & 1 deletion README.zh-Hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ import "echarts";

```html
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/echarts@5.5.1"></script>
<script src="https://cdn.jsdelivr.net/npm/echarts@6.0.0-beta.1"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
```

Expand Down Expand Up @@ -331,6 +331,12 @@ export default {
- `clear` [](https://echarts.apache.org/zh/api.html#echartsInstance.clear)
- `dispose` [](https://echarts.apache.org/zh/api.html#echartsInstance.dispose)

> [!NOTE]
> 如下 ECharts 实例方法没有被暴露,因为它们的功能已经通过组件 [props](#props) 提供了:
>
> - [`showLoading`](https://echarts.apache.org/zh/api.html#echartsInstance.showLoading) / [`hideLoading`](https://echarts.apache.org/zh/api.html#echartsInstance.hideLoading):请使用 `loading``loading-options` prop。
> - `setTheme`:请使用 `theme` prop。
### 静态方法

静态方法请直接通过 [`echarts` 本身](https://echarts.apache.org/zh/api.html#echarts)进行调用。
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"docs": "node ./scripts/docs.mjs",
"prepublishOnly": "pnpm run typecheck && pnpm run dev:typecheck && pnpm run build && publint"
},
"packageManager": "pnpm@10.11.0",
"packageManager": "pnpm@10.12.4",
"type": "module",
"main": "dist/index.js",
"unpkg": "dist/index.min.js",
Expand All @@ -36,7 +36,7 @@
"dist"
],
"peerDependencies": {
"echarts": "^5.5.1",
"echarts": "^6.0.0-beta.1",
"vue": "^3.1.1"
},
"devDependencies": {
Expand All @@ -50,7 +50,7 @@
"@vue/tsconfig": "^0.7.0",
"@vueuse/core": "^13.1.0",
"comment-mark": "^2.0.1",
"echarts": "^5.5.1",
"echarts": "^6.0.0-beta.1",
"echarts-gl": "^2.0.9",
"echarts-liquidfill": "^3.1.0",
"esbuild-wasm": "^0.23.0",
Expand Down
31 changes: 19 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/docs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const CDN_PREFIX = "https://cdn.jsdelivr.net/npm/";

const DEP_VERSIONS = {
vue: "3.5.13",
echarts: "5.5.1",
echarts: "6.0.0-beta.1",
[name]: version,
};

Expand Down
12 changes: 11 additions & 1 deletion src/ECharts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export default defineComponent({
);

watch(
[realTheme, realInitOptions],
realInitOptions,
() => {
cleanup();
init();
Expand All @@ -262,6 +262,16 @@ export default defineComponent({
},
);

watch(
realTheme,
(theme) => {
chart.value?.setTheme(theme);
},
{
deep: true,
},
);

watchEffect(() => {
if (props.group && chart.value) {
chart.value.group = props.group;
Expand Down