From 989e285af5044cb1a24b777233cf5659cfd93921 Mon Sep 17 00:00:00 2001 From: Bluepr1nt Date: Tue, 11 Apr 2017 16:13:04 +0200 Subject: [PATCH] pie chart dashboard --- mean-app/src/app/dashboard.component.html | 19 +++++-- mean-app/src/app/dashboard.component.ts | 63 ++++++++++++++++++++++- mean-app/src/app/piechart.component.html | 6 +++ mean-app/src/app/piechart.component.ts | 43 ++++++++++++++++ 4 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 mean-app/src/app/piechart.component.html create mode 100644 mean-app/src/app/piechart.component.ts diff --git a/mean-app/src/app/dashboard.component.html b/mean-app/src/app/dashboard.component.html index 60b661b..40b46c0 100644 --- a/mean-app/src/app/dashboard.component.html +++ b/mean-app/src/app/dashboard.component.html @@ -1,3 +1,16 @@ -
- -
\ No newline at end of file + + +
+

Martijn

+ +
+ +
+ + +
+

Kenneth

+ +
+ +
diff --git a/mean-app/src/app/dashboard.component.ts b/mean-app/src/app/dashboard.component.ts index 9d1ca74..b485a2d 100644 --- a/mean-app/src/app/dashboard.component.ts +++ b/mean-app/src/app/dashboard.component.ts @@ -1,10 +1,69 @@ -import { Component } from '@angular/core'; +import {Component, OnDestroy, OnInit} from '@angular/core'; + +import { IntervalObservable } from 'rxjs/observable/IntervalObservable'; +import { Subscription } from 'rxjs/Subscription'; + +import { DataService } from './data.service'; +import {LineChartComponent} from "./chart.component"; +import {LineData} from "./line-data"; +import {LabelData} from "./label-data"; +import {Line} from "tslint/lib/test/lines"; @Component({ selector: 'dashboard', templateUrl: './dashboard.component.html' }) -export class DashboardComponent { +export class DashboardComponent implements OnInit, OnDestroy { + public data1:LineData; + public data2:LineData; + public mloaded:boolean = false; + public kloaded:boolean = false; + + public subscription:Subscription; + + constructor(private dataService: DataService) {} + + ngOnInit(): void { + + this.refreshData(); + + this.subscription = IntervalObservable.create(7500).subscribe(n => this.refreshData()); + + } + + ngOnDestroy(): void { + this.subscription.unsubscribe(); + } + + refreshData() + { + console.log("Refreshing data"); + + this.dataService + .usage("4530303035303031353538313833363134") + .subscribe(res => { + + this.data1 = ({data: [res.HOV, res.HTV], label: "Verbruik Martijn"}); + this.mloaded = true; + + }); + + this.dataService + .usage("4530303235303030303636383733323136") + .subscribe(res => { + + this.data2 = ({data: [res.HOV, res.HTV], label: "Verbruik Kenneth"}); + this.kloaded = true; + + }); + + this.dataService + .get("4530303235303030303636383733323136") + .subscribe(res => { + + }); + + } } diff --git a/mean-app/src/app/piechart.component.html b/mean-app/src/app/piechart.component.html new file mode 100644 index 0000000..9024f24 --- /dev/null +++ b/mean-app/src/app/piechart.component.html @@ -0,0 +1,6 @@ +
+ +
diff --git a/mean-app/src/app/piechart.component.ts b/mean-app/src/app/piechart.component.ts new file mode 100644 index 0000000..33dfc4c --- /dev/null +++ b/mean-app/src/app/piechart.component.ts @@ -0,0 +1,43 @@ +import { Component, OnInit, OnChanges, ViewChild, ElementRef,Input } from '@angular/core'; +import { DataService } from './data.service'; + +import { LineData } from './line-data'; +import { BaseChartDirective } from 'ng2-charts/ng2-charts'; +import {LabelData} from "./label-data"; + +@Component({ + selector: 'pie-chart', + templateUrl: './piechart.component.html' +}) +export class PieChartComponent implements OnInit, OnChanges { + + @Input()data:LineData; + @Input()label:LabelData; + + @ViewChild(BaseChartDirective) public chart: BaseChartDirective; + + // lineChart + public pieChartData:Array = [0,0]; + public pieChartLabels:Array = ['-1', '-2']; + public pieChartType:string = 'pie'; + + constructor(private dataService: DataService) {} + + ngOnInit(): void { + + this.pieChartLabels = this.label.data.slice(); + + const newDataSet = []; + newDataSet.push(this.data.data); + this.pieChartData = newDataSet; + } + + ngOnChanges(): void { + if(this.chart.chart != undefined){ + this.chart.chart.update(); + } + + } + + +}