forked from apexcharts/ng-apexcharts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.component.ts
64 lines (58 loc) · 1.91 KB
/
app.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import {Component, ViewChild} from '@angular/core';
import {FormArray, FormControl, FormGroup} from '@angular/forms';
import {ChartComponent} from 'ng-apexcharts';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.less']
})
export class AppComponent {
@ViewChild('chart') chart: ChartComponent;
form: FormGroup;
constructor() {
this.form = new FormGroup({
title: new FormControl('Basic Chart'),
type: new FormControl('line'),
height: new FormControl(350),
series: new FormArray([
new FormGroup({
name: new FormControl('Series'),
type: new FormControl('line'),
data: new FormArray([
new FormControl(this.getRandomArbitrary(0, 100)),
new FormControl(this.getRandomArbitrary(0, 100)),
new FormControl(this.getRandomArbitrary(0, 100)),
new FormControl(this.getRandomArbitrary(0, 100))
])
})
]),
xaxis: new FormArray([
new FormControl('Jan'),
new FormControl('Feb'),
new FormControl('Mar'),
new FormControl('Apr')
])
});
}
addValue() {
(<FormArray>this.form.get('series')).controls.forEach((c) => {
(<FormArray>c.get('data')).push(new FormControl(this.getRandomArbitrary(0, 100)));
});
(<FormArray>this.form.get('xaxis')).push(new FormControl('Jan'));
}
addSeries() {
(<FormArray>this.form.get('series')).push(new FormGroup({
name: new FormControl('Series'),
type: new FormControl('line'),
data: new FormArray([
new FormControl(this.getRandomArbitrary(0, 100)),
new FormControl(this.getRandomArbitrary(0, 100)),
new FormControl(this.getRandomArbitrary(0, 100)),
new FormControl(this.getRandomArbitrary(0, 100))
])
}));
}
private getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
}