项目作者: stack-stark

项目描述 :
g2plot的angular封装 Angular library based on @antv/g2plot
高级语言: TypeScript
项目地址: git://github.com/stack-stark/ngx-g2plot.git
创建时间: 2020-05-07T03:59:48Z
项目社区:https://github.com/stack-stark/ngx-g2plot

开源协议:MIT License

关键词:
angular g2 g2plot ngx ngx-g2plot

下载


NgxG2plot

angular的g2plot封装,方便使用。

安装

  1. npm install --save ngx-g2plot
  2. #or
  3. yarn add ngx-g2plot

在线预览

https://stack-stark.github.io/ngx-g2plot-preview-compiled/

使用

line.component.html

  1. <div starkG2plotLine #divG2plotLine="g2plotLine" [options]="options"></div>

line.component.ts

  1. import { Component, ViewChild } from '@angular/core';
  2. import { G2plotLineDirective } from 'ngx-g2plot';
  3. @Component({
  4. selector: 'app-line',
  5. templateUrl: './line.component.html',
  6. styleUrls: ['./line.component.less']
  7. })
  8. export class LineComponent {
  9. constructor() { }
  10. //获取到指令对象
  11. @ViewChild('divG2plotLine') divG2plotLine!: G2plotLineDirective;
  12. data: Array<object> = [
  13. { year: '1991', value: 3 },
  14. { year: '1992', value: 4 },
  15. { year: '1993', value: 3.5 },
  16. { year: '1994', value: 5 },
  17. { year: '1995', value: 4.9 },
  18. { year: '1996', value: 6 },
  19. { year: '1997', value: 7 },
  20. { year: '1998', value: 9 },
  21. { year: '1999', value: 13 },
  22. ];
  23. options = {
  24. title: {
  25. visible: true,
  26. text: '折线图',
  27. },
  28. description: {
  29. visible: true,
  30. text: '用平滑的曲线代替折线。',
  31. },
  32. data: this.data,
  33. xField: 'year',
  34. yField: 'value',
  35. };
  36. update(): void {
  37. const options = {
  38. title: {
  39. visible: true,
  40. text: 'The line chart',
  41. },
  42. description: {
  43. visible: true,
  44. text: 'Replace broken lines with smooth curves.',
  45. },
  46. xField: 'year',
  47. yField: 'value',
  48. };
  49. this.divG2plotLine.update(options);
  50. }
  51. changeData(): void {
  52. const data = [
  53. { year: '1991', value: 13 },
  54. { year: '1992', value: 14 },
  55. { year: '1993', value: 13.5 },
  56. { year: '1994', value: 15 },
  57. { year: '1995', value: 14.9 },
  58. { year: '1996', value: 16 },
  59. { year: '1997', value: 17 },
  60. { year: '1998', value: 19 },
  61. { year: '1999', value: 23 },
  62. ];
  63. this.divG2plotLine.changeData(data);
  64. }
  65. destroy(): void {
  66. this.divG2plotLine.destroy();
  67. }
  68. changeSize(): void {
  69. //使用当前实例方法
  70. this.divG2plotLine.instance.changeSize(300, 300);
  71. }
  72. }

line.module.ts

  1. import { NgModule } from '@angular/core';
  2. import { CommonModule } from '@angular/common';
  3. import { G2plotLineModule } from 'ngx-g2plot';
  4. @NgModule({
  5. declarations: [G2plotDemoComponent],
  6. imports: [
  7. CommonModule,
  8. G2plotLineModule
  9. ]
  10. })
  11. export class G2plotDemoModule { }

提示

我通过指定exportAs导出update()、changeData()、destroy()这三种方法,以便您可以在任何时候更改图表。使用方法见上面

如果你需要获取当前图表实例及其所有属性和方法,可使用this.xxx.instance,参考见上面的changeSize()

图表所有方法见官方文档: https://g2plot.antv.vision/zh/docs/manual/plot-api

所有指令列表

指令名/Directive 图表名 exportAs Module
starkG2plotArea Area - 面积图 g2plotArea G2plotAreaModule
starkG2plotBar Bar - 基础条形图 g2plotBar G2plotBarModule
starkG2plotBidirectionalBar BidirectionalBar - 对称条形图 g2plotBidirectionalBar G2plotBidirectionalBarModule
starkG2plotBox Box - 箱图 g2plotBox G2plotBoxModule
starkG2plotBullet Bullet - 子弹图 g2plotBullet G2plotBulletModule
starkG2plotChord Chord - 弦图 g2plotChord G2plotChordModule
starkG2plotColumn Column - 柱状图 g2plotColumn G2plotColumnModule
starkG2plotDualAxes DualAxes - 柱线混合图 g2plotDualAxes G2plotDualAxesModule
starkG2plotFunnel Funnel - 漏斗图 g2plotFunnel G2plotFunnelModule
starkG2plotGauge Gauge - 仪表盘 g2plotGauge G2plotGaugeModule
starkG2plotHeatmap Heatmap - 热力图 g2plotHeatmap G2plotHeatmapModule
starkG2plotHistogram Histogram - 直方图 g2plotHistogram G2plotHistogramModule
starkG2plotLine Line - 折线图 g2plotLine G2plotLineModule
starkG2plotLiquid Liquid - 水波图 g2plotLiquid G2plotLiquidModule
starkG2plotPie Pie - 饼图 g2plotPie G2plotPieModule
starkG2plotRadialBar RadialBar - 玉珏图 g2plotRadialBar G2plotRadialBarModule
starkG2plotRadar Radar - 雷达图 g2plotRadar G2plotRadarModule
starkG2plotRose Rose - 玫瑰图 g2plotRose G2plotRoseModule
starkG2plotSankey Sankey - 桑基图 g2plotSankey G2plotSankeyModule
starkG2plotScatter Scatter - 散点图 g2plotScatter G2plotScatterModule
starkG2plotStock Stock - 股票图 g2plotStock G2plotStockModule
starkG2plotSunburst Sunburst - 旭日图图 g2plotSunburst G2plotSunburstModule
starkG2plotTinyColumn TinyColumn - 迷你图 g2plotTinyColumn G2plotTinyColumnModule
starkG2plotTreemap Treemap - 树图 g2plotTreemap G2plotTreemapModule
starkG2plotWaterfall Waterfall - 瀑布图 g2plotWaterfall G2plotWaterfallModule
starkG2plotWordCloud WordCloud - 词云 g2plotWordCloud G2plotWordCloudModule

关于命名

指令名为 starkG2plot + 官方图表名称, exportAs导出为g2plot + 官方图表名称, Module为 G2plot + 官方图表名称 + Module

g2plot官方文档地址

https://g2plot.antv.vision/zh/docs/manual/introduction

使用遇到了问题或者缺陷?

https://github.com/stack-stark/ngx-g2plot/issues

License

MIT