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

docs: update custom theme #5492

Merged
merged 1 commit into from
Aug 31, 2023
Merged
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
63 changes: 62 additions & 1 deletion site/docs/manual/core/theme.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,65 @@ chart.theme({ type: 'classicDark' }); // 使用暗色主题

## 自定义主题

> 该功能还没有稳定...
有两种自定义主题的方式,第一种是在 theme 指定希望覆盖某些主题样式:

```js
const theme = {};

// Spec 形式
const options = {
theme: {
type: 'light',
...theme,
},
};

// API 形式
chart.theme({ type: 'light', ...theme });
```

下面的例子覆盖了 light 主题的默认颜色:

```js | ob
(() => {
const chart = new G2.Chart();

chart.options({
type: 'interval',
data: {
type: 'fetch',
value:
'https://gw.alipayobjects.com/os/bmw-prod/fb9db6b7-23a5-4c23-bbef-c54a55fee580.csv',
},
encode: { x: 'letter', y: 'frequency' },
axis: { y: { labelFormatter: '.0%' } },
theme: {
color: 'red', // 设置默认颜色为红色
},
});

chart.render();

return chart.getContainer();
})();
```

如果希望自定义所有的主题样式,可以新增一个主题,注册,然后使用。

```js
import { register } from '@antv/g2';

const theme = {};

register('theme.custom', theme);

// Spec 形式
const options = {
theme: { type: 'custom' },
};

// API 形式
chart.theme({ type: 'custom' });
```

完整的主题配置可以参考 [light](https://github.com/antvis/G2/blob/v5/src/theme/light.ts) 主题。
Loading