项目作者: samcodex

项目描述 :
Angular 4 curved line chart component
高级语言: TypeScript
项目地址: git://github.com/samcodex/ng-ax-path.git
创建时间: 2017-11-06T16:45:23Z
项目社区:https://github.com/samcodex/ng-ax-path

开源协议:MIT License

下载


ng-ax-path

Angular curved line chart component for web and Ionic application

Description

ng-ax-path creates a curved line chart with two dimensions base on the passing individual data points.
Compatible with Ionic 2, Angular2 and Angular4 versions.

Display legend inside the chart


Legend_In_Block


Display legend outside the chart


Legend_Out_Block


Display legend on top of the chart


Legend_Out_Center

Installation

npm install ng-ax-path —save

Usage

import NgCanvasModule inside your module to be able to use ng-ax-path component.

  1. import { NgCanvasModule } from 'ng-ax-path';
  2. @NgModule({
  3. imports: [
  4. ...
  5. NgCanvasModule
  6. ],
  7. ...
  8. })
  9. export class YourModule {}

Code Examples

  1. add ng-ax-path component into html template - app.component.html

  2. set ng-ax-path data in component class - app.component.ts
    ```ts
    import { Component, OnInit } from ‘@angular/core’;
    import { Http } from ‘@angular/http’;
    import { Observable } from ‘rxjs/Observable’;
    import ‘rxjs/add/operator/map’;

import { Canvas, Axis, Path, Point, LegendStyle, LegendShape, PathType, PointShape, CanvasStyle, SVG_ELEMENT_TYPE } from ‘../../../src’;

@Component({
selector: ‘app-root’,
templateUrl: ‘./app.component.html’,
styleUrls: [‘./app.component.css’]
})
export class AppComponent implements OnInit {
title = ‘app’;
canvas: Canvas;

constructor(private http: Http) {}

ngOnInit() {
const canvas = this.canvas = new Canvas(‘Demo’, {width: 600, height: 400}, CanvasStyle.Coordinate, [30, 130]);
canvas.legendShape = LegendShape.CIRCLE;
canvas.legend = LegendStyle.BOTTOM_CENTER_OUT_LINE;
// canvas.defaultMargin = {left:0, top: 0, right: 1, bottom: 1};

  1. // xAxis.options.disableAxisLine = true;
  2. canvas.createX('Time', 'months', {tickInterval: 3, extraSpace: 3});
  3. canvas.yAxis = new Axis(SVG_ELEMENT_TYPE.AXIS_Y, 'Weight', 'kg', {extraSpace: 10});
  4. const xAxis = canvas.getX();
  5. xAxis.options.tickInterval = 3;
  6. const yAxis = canvas.getY();
  7. // add path from Path instance
  8. const data = [[0,0],[3,10],[6,18],[9,16],[12,22],[13,26],[15,30],[18,40],[20,60],[22,62],[24,50]];
  9. const points: Point[] = data.map(d=>new Point( d[0], d[1] ));
  10. const path = new Path(points, 'Data Set 1 - 2014');
  11. canvas.addPath(path);
  12. // add path from tuple[number, number]
  13. const data2: [number, number][] = [[2,10],[4,18],[7,26],[9,60],[10,40],[12,60],[16,80], [18,90], [20,120]];
  14. const path2 = canvas.addPath(data2, 'Data 2');
  15. path2.color = 'red';
  16. path2.pointShape = PointShape.SQUARE;
  17. // add path from Points[]
  18. const data3 = [[2,53],[4,57],[7,64],[9,73],[10,84],[12,100],[16,97], [18,102], [20,78], [22,68]];
  19. const points3: Point[] = data3.map(d=>new Point( d[0], d[1] ));
  20. const path3 = canvas.addPath(points3, 'Data 3');
  21. path3.color = 'blue';
  22. path3.hasDot = false;
  23. // add path with Observable
  24. // this.http.get('assets/data/data1.json').subscribe(d=> {
  25. // canvas.addPath(d.json(), 'Data from Json').color = 'purple';
  26. // canvas.buildGroup();
  27. // });
  28. // Observable, data format [[number, number]]
  29. const path4 = canvas.addPath(
  30. this.http.get('assets/data/data1.json')
  31. .map(d => <[number, number][]>d.json()),
  32. 'Data from Json'
  33. );
  34. path4.color = 'purple';
  35. path4.pathType = PathType.STRAIGHT_LINE;
  36. path4.pointShape = PointShape.TRIANGLE;
  37. // Observable, data format [{x,y}]
  38. canvas.addPath(
  39. this.http.get('assets/data/data2.json')
  40. .map( d => <{x: number, y: number}[]>d.json().map(c => ({ x: c[0], y: c[1] }))),
  41. 'Data Set 5 Json'
  42. ).color = 'green';

}
}

  1. ## Canvas Style

CanvasStyle.Coordinate // with canvas title, legend, axis line, tick line
CanvasStyle.CanvasBoard // with tick line, no title, legend and axis line

  1. ## Legend Shape

LegendShape.LINE
LegendShape.CIRCLE
LegendShape.RECTANGLE
LegendShape.ELLIPSE

  1. ## Legend Style

LegendStyle.UP_LEFT_IN_BLOCK
LegendStyle.UP_LEFT_IN_LINE
LegendStyle.UP_RIGHT_IN_BLOCK
LegendStyle.UP_RIGHT_IN_LINE
LegendStyle.BOTTOM_LEFT_IN_BLOCK
LegendStyle.BOTTOM_LEFT_IN_LINE
LegendStyle.BOTTOM_RIGHT_IN_BLOCK
LegendStyle.BOTTOM_RIGHT_IN_LINE
LegendStyle.UP_CENTER_IN_LINE
LegendStyle.BOTTOM_CENTER_IN_LINE
LegendStyle.UP_CENTER_OUT_LINE
LegendStyle.UP_LEFT_OUT_LINE
LegendStyle.UP_RIGHT_OUT_LINE
LegendStyle.BOTTOM_CENTER_OUT_LINE
LegendStyle.UP_LEFT_SIDE_BLOCK
LegendStyle.UP_RIGHT_SIDE_BLOCK
LegendStyle.BOTTOM_LEFT_SIDE_BLOCK
LegendStyle.BOTTOM_RIGHT_SIDE_BLOCK
```

Built With

Authors

Samuel Xie