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

g2-mini-bar 迷你柱状图

迷你柱状图更适合展示简单的区间数据,简洁的表现方式可以很好的减少大数据量的视觉展现压力。

  1. import { G2MiniBarModule } from '@delon/chart/mini-bar';

代码演示

g2-mini-bar 迷你柱状图 - 图3

基础

基础用法。

  1. import { Component, OnInit } from '@angular/core';
  2. import { G2MiniBarClickItem, G2MiniBarData } from '@delon/chart/mini-bar';
  3. import format from 'date-fns/format';
  4. import { NzMessageService } from 'ng-zorro-antd/message';
  5. @Component({
  6. selector: 'chart-mini-bar-basic',
  7. template: ` <g2-mini-bar height="45" [data]="visitData" (clickItem)="handleClick($event)"></g2-mini-bar> `,
  8. })
  9. export class ChartMiniBarBasicComponent implements OnInit {
  10. visitData: G2MiniBarData[] = [];
  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: G2MiniBarClickItem): void {
  22. this.msg.info(`${data.item.x} - ${data.item.y}`);
  23. }
  24. }

g2-mini-bar 迷你柱状图 - 图4

Tooltip

指定 yTooltipSuffix 值来表示单位。

  1. import { Component, OnInit } from '@angular/core';
  2. import { G2MiniBarData } from '@delon/chart/mini-bar';
  3. import format from 'date-fns/format';
  4. @Component({
  5. selector: 'chart-mini-bar-tooltip',
  6. template: ` <g2-mini-bar height="45" [data]="visitData" yTooltipSuffix="%"></g2-mini-bar> `,
  7. })
  8. export class ChartMiniBarTooltipComponent implements OnInit {
  9. visitData: G2MiniBarData[] = [];
  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-bar 迷你柱状图 - 图5

Mini tooltip

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

  1. import { Component, OnInit } from '@angular/core';
  2. import { G2MiniBarData } from '@delon/chart/mini-bar';
  3. import format from 'date-fns/format';
  4. @Component({
  5. selector: 'chart-mini-bar-mini',
  6. template: ` <g2-mini-bar height="45" [data]="visitData" yTooltipSuffix="%" tooltipType="mini"></g2-mini-bar> `,
  7. })
  8. export class ChartMiniBarMiniComponent implements OnInit {
  9. visitData: G2MiniBarData[] = [];
  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-bar

参数说明类型默认值
[delay]延迟渲染,单位:毫秒number0
[color]图表颜色string#1890FF
[height]图表高度number-
[yTooltipSuffix]y 轴Tooltip后缀,一般指定单位string-
[tooltipType]Tooltip显示类型‘mini’,’default’‘default’
[borderWidth]线条粗细number5
[padding]图表内部间距array[8, 8, 8, 8]
[data]数据G2MiniBarData[]-
[theme]定制图表主题string | LooseObject-
(clickItem)点击项回调EventEmitter<G2MiniBarClickItem>-

G2MiniBarData

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