Skip to content

Commit fa80e23

Browse files
committed
updated demo
fixed default values for options added auto update series updated README.md
1 parent 980861f commit fa80e23

File tree

11 files changed

+175
-70
lines changed

11 files changed

+175
-70
lines changed

README.md

+23-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,14 @@ imports: [
4343
In any component you can use the chart using:
4444

4545
```` html
46-
<apx-chart></apx-chart>
46+
<apx-chart [series]="series" [chart]="chart" [title]="title"></apx-chart>
4747
````
4848

49+
You need to provide at least the series and chart attribute to make sure the
50+
chart can get created.
51+
52+
You can also use any other attribute from the following options.
53+
4954
### Options
5055

5156
All options of the chart can inserted using the attributes.
@@ -73,19 +78,34 @@ This is a list of all available attributes:
7378
@Input() theme: ApexTheme;
7479
````
7580

81+
#### Auto update series
82+
83+
With the attribute `autoUpdateSeries` you can control if the chart component should
84+
call the `updateSeries` function automatically if the series attribute is changed.
85+
Set this attribute to false if you are using and changig the type property in your
86+
series for a mixed chart. This only has the effect that the whole chart rerenders
87+
even if only the series changes.
7688

7789
### Use methods
7890

79-
If you want to access the methods of the components use this in your component:
91+
For a basic usage of the charts you dont need to use the methods of the chart.
92+
93+
But if you want to toggle a series for example you need to call them. All methods
94+
are proxied through the component so that you dont need to access the DOM by
95+
yourself.
96+
97+
Just reference the component as a ViewChild in your Component by using:
8098
```` ts
8199
@ViewChild('chartObj') chart: ChartComponent;
82100
````
83101

84-
and change the template to this:
102+
and chaning the template to this:
85103
```` html
86104
<apx-chart #chartObj></apx-chart>
87105
````
88106

107+
Now you're able to call methods from your Component.
108+
89109
## Author
90110

91111
[Morris Janatzek](http://morrisj.net) ([morrisjdev](https://github.com/morrisjdev))

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"@angular/platform-browser": "~7.1.0",
2020
"@angular/platform-browser-dynamic": "~7.1.0",
2121
"@angular/router": "~7.1.0",
22-
"apexcharts": "^3.2.2",
22+
"apexcharts": "^3.3.1",
2323
"core-js": "^2.5.4",
2424
"rxjs": "~6.3.3",
2525
"tslib": "^1.9.0",

projects/ng-apexcharts/README.md

+37-11
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
1+
<p align="center">
2+
<img src="https://morrisj.net/storage/icons/ng-apexcharts/icon.svg" width="180" />
3+
</p>
4+
15
# ng-apexcharts
26

3-
ng-apexcharts is an implementation of apexcharts for angular.
7+
ng-apexcharts is an implementation of [apexcharts](https://apexcharts.com/) for angular.
48
It comes with one simple component that enables you to use apexcharts
59
in an angular project.
610

11+
For a demo checkout: <a href="https://ngapexcharts-demo.stackblitz.io/" target="_blank">Stackblitz example</a>
12+
713
## Installation
814

915
1. Install using npm:
1016

11-
````
17+
```` ts
1218
npm install apexcharts ng-apexcharts --save
1319
````
1420

1521
2. Open angular.json and under scripts add:
1622

17-
````
23+
```` ts
1824
"scripts": [
1925
"node_modules/apexcharts/dist/apexcharts.min.js"
2026
]
2127
````
2228

2329
3. Add ng-apexcharts-module to imports
2430

25-
````
31+
```` ts
2632
imports: [
2733
BrowserModule,
2834
FormsModule,
@@ -36,16 +42,21 @@ imports: [
3642

3743
In any component you can use the chart using:
3844

45+
```` html
46+
<apx-chart [series]="series" [chart]="chart" [title]="title"></apx-chart>
3947
````
40-
<apx-chart></apx-chart>
41-
````
48+
49+
You need to provide at least the series and chart attribute to make sure the
50+
chart can get created.
51+
52+
You can also use any other attribute from the following options.
4253

4354
### Options
4455

4556
All options of the chart can inserted using the attributes.
4657
This is a list of all available attributes:
4758

48-
````
59+
```` ts
4960
@Input() chart: ApexChart;
5061
@Input() annotations: ApexAnnotations;
5162
@Input() colors: string[];
@@ -67,19 +78,34 @@ This is a list of all available attributes:
6778
@Input() theme: ApexTheme;
6879
````
6980

81+
#### Auto update series
82+
83+
With the attribute `autoUpdateSeries` you can control if the chart component should
84+
call the `updateSeries` function automatically if the series attribute is changed.
85+
Set this attribute to false if you are using and changig the type property in your
86+
series for a mixed chart. This only has the effect that the whole chart rerenders
87+
even if only the series changes.
7088

7189
### Use methods
7290

73-
If you want to access the methods of the components use this in your component:
74-
````
91+
For a basic usage of the charts you dont need to use the methods of the chart.
92+
93+
But if you want to toggle a series for example you need to call them. All methods
94+
are proxied through the component so that you dont need to access the DOM by
95+
yourself.
96+
97+
Just reference the component as a ViewChild in your Component by using:
98+
```` ts
7599
@ViewChild('chartObj') chart: ChartComponent;
76100
````
77101

78-
and change the template to this:
79-
````
102+
and chaning the template to this:
103+
```` html
80104
<apx-chart #chartObj></apx-chart>
81105
````
82106

107+
Now you're able to call methods from your Component.
108+
83109
## Author
84110

85111
[Morris Janatzek](http://morrisj.net) ([morrisjdev](https://github.com/morrisjdev))

projects/ng-apexcharts/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "ng-apexcharts",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "an angular implementation of apexcharts",
55
"peerDependencies": {
66
"@angular/common": "^7.1.0",
77
"@angular/core": "^7.1.0",
8-
"apexcharts": "3.2.2"
8+
"apexcharts": "^3.3.1"
99
},
1010
"keywords": [
1111
"angular",

projects/ng-apexcharts/src/lib/chart/chart.component.ts

+17-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ export class ChartComponent implements OnInit, OnChanges {
2828
@Input() chart: ApexChart;
2929
@Input() annotations: ApexAnnotations;
3030
@Input() colors: string[];
31-
@Input() dataLabels: ApexDataLabels;
31+
@Input() dataLabels: ApexDataLabels = {enabled: false};
3232
@Input() series: ApexAxisChartSeries | ApexNonAxisChartSeries;
33-
@Input() stroke: ApexStroke;
33+
@Input() stroke: ApexStroke = {curve: 'straight'};
3434
@Input() labels: string[];
3535
@Input() legend: ApexLegend;
3636
@Input() fill: ApexFill;
@@ -39,12 +39,21 @@ export class ChartComponent implements OnInit, OnChanges {
3939
@Input() responsive: ApexResponsive[];
4040
@Input() xaxis: ApexXAxis;
4141
@Input() yaxis: ApexYAxis | ApexYAxis[];
42-
@Input() grid: ApexGrid;
42+
43+
@Input() grid: ApexGrid = {
44+
row: {
45+
colors: ['#f3f3f3', 'transparent'],
46+
opacity: 0.5
47+
}
48+
};
49+
4350
@Input() states: ApexStates;
4451
@Input() title: ApexTitleSubtitle;
4552
@Input() subtitle: ApexTitleSubtitle;
4653
@Input() theme: ApexTheme;
4754

55+
@Input() autoUpdateSeries = true;
56+
4857
@ViewChild('chart') private chartElement: ElementRef;
4958
private chartObj: any;
5059

@@ -56,6 +65,11 @@ export class ChartComponent implements OnInit, OnChanges {
5665

5766
ngOnChanges(changes: SimpleChanges): void {
5867
setTimeout(() => {
68+
if (this.autoUpdateSeries && Object.keys(changes).filter(c => c !== 'series').length === 0) {
69+
this.updateSeries(this.series, true);
70+
return;
71+
}
72+
5973
this.createElement();
6074
}, 0);
6175
}

src/app/app.component.html

+34-31
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
<!--The content below is only a placeholder and can be replaced.-->
2-
<apx-chart #firstChart [series]="[form.value.series]"
1+
<apx-chart #chart [series]="form.value.series | series: form.value.type"
32
[xaxis]="{ categories: form.value.xaxis }"
43
[chart]="{
5-
height: height,
6-
type: 'line',
4+
height: form.value.height,
5+
type: form.value.type,
76
zoom: {
87
enabled: false
98
},
@@ -15,42 +14,48 @@
1514
blur: 10,
1615
opacity: 1
1716
}}"
18-
19-
[grid]="{
20-
row: {
21-
colors: ['#f3f3f3', 'transparent'],
22-
opacity: 0.5
23-
}
24-
}"
25-
[title]="{ text: 'Product Trends by Month', align: 'left' }"
26-
[stroke]="{curve: 'straight'}" [dataLabels]="{enabled: false}">
27-
28-
</apx-chart>
29-
30-
<input type="number" [(ngModel)]="height">
17+
[title]="{ text: form.value.title }" [autoUpdateSeries]="false"></apx-chart>
3118

3219
<form [formGroup]="form">
33-
<div formGroupName="series">
34-
<input type="text" formControlName="name">
35-
</div>
36-
20+
Title: <input type="text" formControlName="title"><br>
21+
Height: <input type="number" formControlName="height"><br>
22+
Type: <select formControlName="type">
23+
<option value="line">Line</option>
24+
<option value="area">Area</option>
25+
<option value="bar">Bar</option>
26+
<option value="radar">Radar</option>
27+
</select>
3728

3829
<h3>Values</h3>
39-
<button (click)="addValue()">Add Value</button>
30+
<button (click)="addSeries()">Add series</button>
31+
<button (click)="addValue()">Add value</button>
4032

4133
<div>
42-
<div formGroupName="series" style="width: 20%; display: inline-block">
43-
<div formArrayName="data">
44-
<div *ngFor="let alias of form.get('series').get('data').controls; let i=index">
45-
<label>
46-
Value:
47-
<input type="number" [formControlName]="i">
48-
</label>
34+
<div style="width: 80%; display: inline-block;" formArrayName="series">
35+
<h4>Data</h4>
36+
37+
<div *ngFor="let series of form.get('series').controls; let i = index" style="width: 20%; display: inline-block">
38+
<div [formGroupName]="i">
39+
Name: <input type="text" formControlName="name"><br>
40+
Type: <select formControlName="type">
41+
<option value="line">Line</option>
42+
<option value="area">Area</option>
43+
<option value="bar">Bar</option>
44+
</select>
45+
46+
<div formArrayName="data">
47+
<div *ngFor="let alias of form.get('series').controls[i].get('data').controls; let y=index">
48+
<label>
49+
Value: <input type="number" [formControlName]="y">
50+
</label>
51+
</div>
52+
</div>
4953
</div>
5054
</div>
5155
</div>
5256

5357
<div formArrayName="xaxis" style="width: 20%; display: inline-block">
58+
<h4>XAxis</h4>
5459
<div *ngFor="let alias of form.get('xaxis').controls; let i=index">
5560
<label>
5661
Value:
@@ -61,8 +66,6 @@ <h3>Values</h3>
6166
</div>
6267
</form>
6368

64-
<button type="button" (click)="execute()">Execute</button><br>
65-
6669
{{form.value | json}}
6770

6871
<router-outlet></router-outlet>

0 commit comments

Comments
 (0)