Konstantinos Kamaropoulos
5 years ago
15 changed files with 17740 additions and 20 deletions
@ -0,0 +1,17 @@ |
|||
import { NgModule } from '@angular/core'; |
|||
import { Routes, RouterModule } from '@angular/router'; |
|||
|
|||
import { extract } from '@app/core'; |
|||
import { ChartComponent } from './chart.component'; |
|||
|
|||
const routes: Routes = [ |
|||
// Module is lazy loaded, see app-routing.module.ts
|
|||
{ path: '', component: ChartComponent, data: { title: extract('Chart') } } |
|||
]; |
|||
|
|||
@NgModule({ |
|||
imports: [RouterModule.forChild(routes)], |
|||
exports: [RouterModule], |
|||
providers: [] |
|||
}) |
|||
export class ChartRoutingModule {} |
@ -0,0 +1 @@ |
|||
<div id="chartContainer" style="height: 85vh; width: 100%; margin-left:auto;margin-right:auto;"></div> |
@ -0,0 +1,24 @@ |
|||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; |
|||
|
|||
import { ChartComponent } from './chart.component'; |
|||
|
|||
describe('ChartComponent', () => { |
|||
let component: ChartComponent; |
|||
let fixture: ComponentFixture<ChartComponent>; |
|||
|
|||
beforeEach(async(() => { |
|||
TestBed.configureTestingModule({ |
|||
declarations: [ChartComponent] |
|||
}).compileComponents(); |
|||
})); |
|||
|
|||
beforeEach(() => { |
|||
fixture = TestBed.createComponent(ChartComponent); |
|||
component = fixture.componentInstance; |
|||
fixture.detectChanges(); |
|||
}); |
|||
|
|||
it('should create', () => { |
|||
expect(component).toBeTruthy(); |
|||
}); |
|||
}); |
@ -0,0 +1,83 @@ |
|||
import { Component, OnInit } from '@angular/core'; |
|||
// Dirty fix for `require` type definition
|
|||
declare var require: any; |
|||
const CanvasJS = require('../../assets/canvasjs.min'); |
|||
import { LogsService } from '@app/logs.service'; |
|||
import { interval } from 'rxjs'; |
|||
|
|||
@Component({ |
|||
selector: 'app-chart', |
|||
templateUrl: './chart.component.html', |
|||
styleUrls: ['./chart.component.scss'] |
|||
}) |
|||
export class ChartComponent implements OnInit { |
|||
sub: any; |
|||
|
|||
constructor(private logsService: LogsService) {} |
|||
|
|||
dataPoints: any[] = []; |
|||
|
|||
async ngOnInit() { |
|||
let dpsLength = 0; |
|||
let chart = new CanvasJS.Chart('chartContainer', { |
|||
zoomEnabled: true, |
|||
animationEnabled: true, |
|||
exportEnabled: true, |
|||
title: { |
|||
text: '' |
|||
}, |
|||
data: [ |
|||
{ |
|||
type: 'spline', |
|||
dataPoints: this.dataPoints |
|||
} |
|||
] |
|||
}); |
|||
|
|||
let data = await this.logsService.getUpdates(); |
|||
let mq2: any = data.map(log => { |
|||
return log['sensorReadings']['MQ2']; |
|||
}); |
|||
|
|||
let i = 0; |
|||
mq2.forEach((value: any) => { |
|||
this.dataPoints.push({ x: ++i, y: parseInt(value) }); |
|||
}); |
|||
dpsLength = this.dataPoints.length; |
|||
chart.render(); |
|||
this.sub = interval(1000).subscribe(async val => { |
|||
let data = await this.logsService.getUpdates(); |
|||
let mq2: any = data.map((log: any) => { |
|||
return log['sensorReadings']['MQ2']; |
|||
}); |
|||
|
|||
let j = i; |
|||
mq2.forEach((value: any) => { |
|||
this.dataPoints.push({ x: ++j, y: parseInt(value) }); |
|||
dpsLength++; |
|||
}); |
|||
i = j; |
|||
|
|||
// if (dataPoints.length > 20 ) {
|
|||
// dataPoints.shift();
|
|||
// }
|
|||
chart.render(); |
|||
}); |
|||
|
|||
// async function updateChart(data:any) {
|
|||
// // let data = await logs.getUpdates();
|
|||
// let mq2:any = data.map((log:any) => {
|
|||
// return log["sensorReadings"]["MQ2"];
|
|||
// });
|
|||
// $.each(mq2, function(key:any, value:any) {
|
|||
// dataPoints.push({x: ++i, y: parseInt(value)});
|
|||
// dpsLength++;
|
|||
// });
|
|||
|
|||
// // if (dataPoints.length > 20 ) {
|
|||
// // dataPoints.shift();
|
|||
// // }
|
|||
// chart.render();
|
|||
// }
|
|||
} |
|||
} |
@ -0,0 +1,12 @@ |
|||
import { NgModule } from '@angular/core'; |
|||
import { CommonModule } from '@angular/common'; |
|||
import { TranslateModule } from '@ngx-translate/core'; |
|||
|
|||
import { ChartRoutingModule } from './chart-routing.module'; |
|||
import { ChartComponent } from './chart.component'; |
|||
|
|||
@NgModule({ |
|||
imports: [CommonModule, TranslateModule, ChartRoutingModule], |
|||
declarations: [ChartComponent] |
|||
}) |
|||
export class ChartModule {} |
File diff suppressed because it is too large
Loading…
Reference in new issue