g2-pie 饼状图 - 图1 This article has not been translated, hope that your can PR to translated it. Help us!g2-pie 饼状图 - 图2

g2-pie 饼状图

用于显示跟速度相关图形再适合不过。

  1. import { G2PieModule } from '@delon/chart/pie';

代码演示

g2-pie 饼状图 - 图3

基础

基础用法。

  1. import { Component, OnInit } from '@angular/core';
  2. import { G2PieClickItem, G2PieData } from '@delon/chart/pie';
  3. import { NzMessageService } from 'ng-zorro-antd/message';
  4. @Component({
  5. selector: 'chart-pie-basic',
  6. template: ` <g2-pie
  7. [hasLegend]="true"
  8. title="销售额"
  9. subTitle="销售额"
  10. [total]="total"
  11. [valueFormat]="format"
  12. [data]="salesPieData"
  13. height="294"
  14. (clickItem)="handleClick($event)"
  15. ></g2-pie>`,
  16. })
  17. export class ChartPieBasicComponent implements OnInit {
  18. salesPieData: G2PieData[] = [
  19. {
  20. x: '家用电器',
  21. y: 4544,
  22. },
  23. {
  24. x: '食用酒水',
  25. y: 3321,
  26. },
  27. {
  28. x: '个护健康',
  29. y: 3113,
  30. },
  31. {
  32. x: '服饰箱包',
  33. y: 2341,
  34. },
  35. {
  36. x: '母婴产品',
  37. y: 1231,
  38. },
  39. {
  40. x: '其他',
  41. y: 1231,
  42. },
  43. ];
  44. total: string;
  45. constructor(private msg: NzMessageService) {}
  46. ngOnInit(): void {
  47. this.total = `&yen ${this.salesPieData.reduce((pre, now) => now.y + pre, 0).toFixed(2)}`;
  48. }
  49. format(val: number) {
  50. return `&yen ${val.toFixed(2)}`;
  51. }
  52. handleClick(data: G2PieClickItem): void {
  53. this.msg.info(`${data.item.x} - ${data.item.y}`);
  54. }
  55. }

g2-pie 饼状图 - 图4

迷你型

通过简化 pie 属性的设置,可以快速的实现极简的饼状图,可配合 chart-card 组合展现更多业务场景。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'chart-pie-mini',
  4. template: `
  5. <div style="width: 200px; display: inline-block">
  6. <g2-pie percent="28" subTitle="中式快餐" total="28%" height="130"></g2-pie>
  7. </div>
  8. `,
  9. })
  10. export class ChartPieMiniComponent {}

API

g2-pie

参数说明类型默认值
[delay]延迟渲染,单位:毫秒number0
[animate]是否显示动画booleantrue
[color]图表颜色stringrgba(24, 144, 255, 0.85)
[height]图表高度number-
[hasLegend]是否显示 legendbooleanfalse
[padding]图表内部间距number[][12, 0, 12, 0]
[percent]占比number-
[lineWidth]边框粗细number0
[inner]内部极坐标系的半径number0.75
[blockMaxWidth]多少宽度为块显示number380
[tooltip]是否显示 tooltipbooleantrue
[subTitle]图表子标题string,TemplateRef<void>-
[total]总量string,TemplateRef<void>-
[valueFormat]y轴格式化(y: number) => string-
[data]数据G2PieData[]-
[interaction]交互类型,none 无 element-active 图形元素,active-region 图表组件,brush 框选,drag-move 移动InteractionTypenone
[theme]定制图表主题string | LooseObject-
(clickItem)点击项回调EventEmitter<G2PieClickItem>-

G2PieData

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