项目作者: jkuri

项目描述 :
Angular Beautiful and Customizable SVG Charts, Line & Area Chart, Realtime Chart, Pie Chart
高级语言: TypeScript
项目地址: git://github.com/jkuri/ngx-graph.git
创建时间: 2020-06-18T11:54:15Z
项目社区:https://github.com/jkuri/ngx-graph

开源协议:MIT License

下载


Angular SVG Charts

This is a set of fully customizable Angular components for visualizing data.

Currently it includes Line/Area Chart, Realtime Line/Area Chart and Pie Chart.

Check live demo.

CodeSandbox Demo - Line Chart

Running Demo Locally

You can run demo app locally, just follow this steps.

  1. git clone https://github.com/jkuri/ngx-graph
  2. cd ngx-graph
  3. npm install // or yarn install
  4. npm start

Installation

Install the npm package.

  1. npm i ngx-graph

Import module that you need.

  1. import { LineChartModule, RealtimeChartModule, PieChartModule } from 'ngx-graph';
  2. @NgModule({
  3. imports: [LineChartModule, RealtimeChartModule, PieChartModule]
  4. })

Line / Area Chart

Preview

Sample of Line / Area Chart:

Screenshot 2020-06-18 at 19 33 45

Usage

This is sample usage of preview above with full source accessible here.

In template:

  1. <ngx-line-chart [options]="options" [data]="data"></ngx-line-chart>

In your component:

  1. import { LineChartData, LineChartOptions } from 'ngx-graph';
  2. options: LineChartOptions = {
  3. height: 300,
  4. margin: { top: 20, right: 40, bottom: 80, left: 60 },
  5. yScale: { min: 0, max: 3000 },
  6. xGrid: {
  7. opacity: .4,
  8. textColor: '#333'
  9. },
  10. yGrid: {
  11. tickPadding: 13,
  12. tickFormat: (num: number) => format('~s')(num) + ' €',
  13. tickTextAnchor: 'end',
  14. tickNumber: 5,
  15. opacity: .4,
  16. textColor: '#333'
  17. },
  18. transitions: true,
  19. transitionDuration: 400,
  20. legend: true,
  21. legendPosition: 'bottom',
  22. legendMargin: { top: 0, right: 0, left: 0, bottom: 0 },
  23. initialTransition: false,
  24. interaction: {
  25. axisLine: true,
  26. axisLineSize: 4,
  27. axisLineColor: '#eef0f7',
  28. tooltip: true,
  29. }
  30. };
  31. data: LineChartData[] = [
  32. new LineChartData({
  33. id: 'progress',
  34. data: this.data.generateRandomDateValues(10, 2000, 2900),
  35. area: true,
  36. areaOpacity: .4,
  37. curve: 'linear',
  38. markers: true,
  39. color: '#FACF55',
  40. areaColor: '#FACF55',
  41. markerColor: '#FACF55',
  42. lineSize: 3
  43. }),
  44. new LineChartData({
  45. id: 'income',
  46. data: this.data.generateRandomDateValues(10, 1200, 1900),
  47. area: true,
  48. areaOpacity: .4,
  49. curve: 'linear',
  50. markers: true,
  51. lineSize: 3
  52. }),
  53. new LineChartData({
  54. id: 'expenses',
  55. data: this.data.generateRandomDateValues(10, 400, 950),
  56. area: true,
  57. areaOpacity: .4,
  58. curve: 'linear',
  59. markers: true,
  60. color: '#34B77C',
  61. areaColor: '#34B77C',
  62. markerColor: '#34B77C',
  63. lineSize: 3
  64. })
  65. ];

For a full list of options please check here.

Real-Time Chart

Preview

ngx-graph-realtime

Usage

For above sample you can check source code here.

In your template:

  1. <ngx-realtime-chart
  2. [options]="realtimeChartOptions"
  3. [data]="realtimeChartData"
  4. ></ngx-realtime-chart>

In your component:

  1. import { interval } from 'rxjs';
  2. import { timeInterval } from 'rxjs/operators';
  3. import { RealtimeChartOptions } from 'ngx-graph';
  4. realtimeChartOptions: RealtimeChartOptions = {
  5. height: 300,
  6. margin: { left: 40 },
  7. lines: [
  8. { color: '#34B77C', lineWidth: 3, area: true, areaColor: '#34B77C', areaOpacity: .2 }
  9. ],
  10. xGrid: { tickPadding: 15, tickNumber: 5 },
  11. yGrid: { min: 0, max: 100, tickNumber: 5, tickFormat: (v: number) => `${v}%`, tickPadding: 25 }
  12. };
  13. ngOnInit(): void {
  14. // push new value to real-time chart every second (example)
  15. interval(1000)
  16. .pipe(timeInterval())
  17. .subscribe(() => {
  18. this.realtimeChartData[0].push({ date: new Date(), value: this.data.randomInt(0, 100) });
  19. })
  20. }

For full list of options please check here.

License

MIT