g2-radar 雷达图 - 图1 This article has not been translated, hope that your can PR to translated it. Help us!g2-radar 雷达图 - 图2

g2-radar 雷达图

雷达图是以相同点开始的轴上表示的三个或更多个定量变量的二维图形的形式显示多变量数据的图形方法。轴的相对位置和角度通常是不知情的。

  1. import { G2RadarModule } from '@delon/chart/radar';

代码演示

g2-radar 雷达图 - 图3

基础

基础用法。

  1. import { Component, OnInit } from '@angular/core';
  2. import { G2RadarClickItem, G2RadarData } from '@delon/chart/radar';
  3. import { NzMessageService } from 'ng-zorro-antd/message';
  4. @Component({
  5. selector: 'chart-radar-basic',
  6. template: ` <g2-radar [hasLegend]="true" [data]="radarData" height="286" (clickItem)="handleClick($event)"></g2-radar>`,
  7. })
  8. export class ChartRadarBasicComponent implements OnInit {
  9. radarData: G2RadarData[] = [];
  10. constructor(private msg: NzMessageService) {}
  11. ngOnInit(): void {
  12. const radarOriginData = [
  13. {
  14. name: '个人',
  15. ref: 10,
  16. koubei: 8,
  17. output: 4,
  18. contribute: 5,
  19. hot: 7,
  20. },
  21. {
  22. name: '团队',
  23. ref: 3,
  24. koubei: 9,
  25. output: 6,
  26. contribute: 3,
  27. hot: 1,
  28. },
  29. {
  30. name: '部门',
  31. ref: 4,
  32. koubei: 1,
  33. output: 6,
  34. contribute: 5,
  35. hot: 7,
  36. },
  37. ];
  38. const radarTitleMap: { [key: string]: string } = {
  39. ref: '引用',
  40. koubei: '口碑',
  41. output: '产量',
  42. contribute: '贡献',
  43. hot: '热度',
  44. };
  45. radarOriginData.forEach((item: { [key: string]: any }) => {
  46. Object.keys(item).forEach(key => {
  47. if (key !== 'name') {
  48. this.radarData.push({
  49. name: item.name,
  50. label: radarTitleMap[key],
  51. value: item[key],
  52. });
  53. }
  54. });
  55. });
  56. }
  57. handleClick(data: G2RadarClickItem): void {
  58. this.msg.info(`${data.item.label} - ${data.item.name} - ${data.item.value}`);
  59. }
  60. }

API

g2-radar

参数说明类型默认值
[delay]延迟渲染,单位:毫秒number0
[title]图表标题string,TemplateRef<void>-
[height]图表高度number-
[hasLegend]是否显示 legendbooleanfalse
[padding]图表内部间距array[24, 30, 16, 30]
[colors]颜色列表string[]-
[data]数据G2RadarData[]-
[theme]定制图表主题string | LooseObject-
(clickItem)点击项回调EventEmitter<G2RadarClickItem>-

G2RadarData

参数说明类型默认值
[name]名称string-
[label]标签string-
[value]number-