8000 feat: add standard chart mount function by moayuisuda · Pull Request #6705 · antvis/G2 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add standard chart mount function #6705

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

Open
wants to merge 1 commit into
base: v5
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions site/docs/manual/core/chart/how-to-use.zh.md
8000
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ const chart = new Chart();
// 声明可视化
// ...

const container = chart.getContainer(); // 获得挂载的容器
document.getElementById('chart').appendChild(container);
chart.mount(document.getElementById('chart'))
```

### 渲染图表
Expand Down
13 changes: 13 additions & 0 deletions src/api/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ export class Runtime<Spec extends G2Spec = G2Spec> extends CompositionNode {
this._create();
}

mount(container: string | HTMLElement) {
const autoFit = this.options['autoFit'];
const chartContainer = this.getContainer();
const normalizedContainer = normalizeContainer(container);

this._container = normalizedContainer;
normalizedContainer.appendChild(chartContainer);

this.forceFit();
// restore autoFit
this.options['autoFit'] = autoFit;
}

render(): Promise<Runtime<Spec>> {
if (this._rendering) return this._addToTrailing();
if (!this._context.canvas) this._createCanvas();
Expand Down
Loading
0