g2-mini-area 迷你区域图 - 图1 This article has not been translated, hope that your can PR to translated it. Help us!g2-mini-area 迷你区域图 - 图2

g2-mini-area 迷你区域图

面积图又叫区域图。 它是在折线图的基础之上形成的, 它将折线图中折线与自变量坐标轴之间的区域使用颜色或者纹理填充,这样一个填充区域我们叫做面积,颜色的填充可以更好的突出趋势信息。

  1. import { G2MiniAreaModule } from '@delon/chart/mini-area';

代码演示

g2-mini-area 迷你区域图 - 图3

基础

基础用法。

  1. import { Component, OnInit } from '@angular/core';
  2. import { G2MiniAreaClickItem, G2MiniAreaData } from '@delon/chart/mini-area';
  3. import format from 'date-fns/format';
  4. import { NzMessageService } from 'ng-zorro-antd/message';
  5. @Component({
  6. selector: 'chart-mini-area-basic',
  7. template: ` <g2-mini-area line color="#cceafe" height="45" [data]="visitData" (clickItem)="handleClick($event)"></g2-mini-area> `,
  8. })
  9. export class ChartMiniAreaBasicComponent implements OnInit {
  10. visitData: G2MiniAreaData[] = [];
  11. constructor(private msg: NzMessageService) {}
  12. ngOnInit(): void {
  13. const beginDay = new Date().getTime();
  14. for (let i = 0; i < 20; i += 1) {
  15. this.visitData.push({
  16. x: format(new Date(beginDay + 1000 * 60 * 60 * 24 * i), 'yyyy-MM-dd'),
  17. y: Math.floor(Math.random() * 100) + 10,
  18. });
  19. }
  20. }
  21. handleClick(data: G2MiniAreaClickItem): void {
  22. this.msg.info(`${data.item.x} - ${data.item.y}`);
  23. }
  24. }

g2-mini-area 迷你区域图 - 图4

Mini tooltip

指定 tooltipType 值来表示简化tooltip,可以更好的运用于表格。

  1. import { Component, OnInit } from '@angular/core';
  2. import { G2MiniAreaData } from '@delon/chart/mini-area';
  3. import format from 'date-fns/format';
  4. @Component({
  5. selector: 'chart-mini-area-mini',
  6. template: ` <g2-mini-area line color="#cceafe" height="45" [data]="visitData" tooltipType="mini"></g2-mini-area> `,
  7. })
  8. export class ChartMiniAreaMiniComponent implements OnInit {
  9. visitData: G2MiniAreaData[] = [];
  10. ngOnInit(): void {
  11. const beginDay = new Date().getTime();
  12. for (let i = 0; i < 20; i += 1) {
  13. this.visitData.push({
  14. x: format(new Date(beginDay + 1000 * 60 * 60 * 24 * i), 'yyyy-MM-dd'),
  15. y: Math.floor(Math.random() * 100) + 10,
  16. });
  17. }
  18. }
  19. }

g2-mini-area 迷你区域图 - 图5

Tooltip

指定 yTooltipSuffix 值来表示单位。

  1. import { Component, OnInit } from '@angular/core';
  2. import { G2MiniAreaData } from '@delon/chart/mini-area';
  3. import format from 'date-fns/format';
  4. @Component({
  5. selector: 'chart-mini-area-tooltip',
  6. template: ` <g2-mini-area line color="#cceafe" height="45" [data]="visitData" yTooltipSuffix="%"></g2-mini-area> `,
  7. })
  8. export class ChartMiniAreaTooltipComponent implements OnInit {
  9. visitData: G2MiniAreaData[] = [];
  10. ngOnInit(): void {
  11. const beginDay = new Date().getTime();
  12. for (let i = 0; i < 20; i += 1) {
  13. this.visitData.push({
  14. x: format(new Date(beginDay + 1000 * 60 * 60 * 24 * i), 'yyyy-MM-dd'),
  15. y: Math.floor(Math.random() * 100) + 10,
  16. });
  17. }
  18. }
  19. }

API

g2-mini-area

参数说明类型默认值
[delay]延迟渲染,单位:毫秒number0
[color]图表颜色stringrgba(24, 144, 255, 0.2)
[borderColor]图表边颜色string#1890FF
[height]图表高度number56
[line]是否显示描边booleanfalse
[animate]是否显示动画booleantrue
[padding]图表内部间距array[8, 8, 8, 8]
[xAxis]x 轴配置object-
[yAxis]y 轴配置object-
[yTooltipSuffix]y 轴Tooltip后缀,一般指定单位string-
[tooltipType]Tooltip显示类型‘mini’,’default’‘default’
[data]数据G2MiniAreaData[]-
[theme]定制图表主题string | LooseObject-
(clickItem)点击项回调EventEmitter<G2MiniAreaClickItem>-

G2MiniAreaData

参数说明类型默认值
[x]x轴any-
[y]y轴any-