ohayolibs
Version:
Ohayo is a set of essential modules for ohayojp.
63 lines (53 loc) • 1.71 kB
Markdown
---
title:
zh-CN: 基础样例
en-US: Basic Usage
type: example
---
## zh-CN
利用 [nz-resizable](https://ng.ant.design/experimental/resizable/zh) 构建一个可调整尺寸的容器。
## en-US
Use [nz-resizable](https://ng.ant.design/experimental/resizable/en) to build a resizable container.
```ts
import { Component, ViewChild } from '@angular/core';
import { G2BarClickItem, G2BarComponent, G2BarData } from '@ohayo/chart/bar';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzResizeEvent } from 'ng-zorro-antd/resizable';
export class DemoComponent {
private readonly barComp: G2BarComponent;
width = 400;
height = 200;
private id = -1;
constructor(private msg: NzMessageService) {}
salesData: G2BarData[] = new Array(12).fill({}).map((_i, idx) => ({
x: `${idx + 1}月`,
y: Math.floor(Math.random() * 1000) + 200,
color: idx > 5 ? '#f50' : undefined,
}));
handleClick(data: G2BarClickItem): void {
this.msg.info(`${data.item.x} - ${data.item.y}`);
}
onResize({ width }: NzResizeEvent): void {
cancelAnimationFrame(this.id);
this.id = requestAnimationFrame(() => {
this.width = width!;
this.barComp.chart.forceFit();
});
}
}
```