added labels
This commit is contained in:
@@ -14,7 +14,12 @@ export class LineChartComponent implements OnInit {
|
||||
];
|
||||
public lineChartLabels:Array<any> = ['January', 'February', 'March', 'April', 'May', 'June', 'July'];
|
||||
public lineChartOptions:any = {
|
||||
responsive: true
|
||||
responsive: true,
|
||||
title: {
|
||||
display: true,
|
||||
position: 'left',
|
||||
text: 'Watt'
|
||||
}
|
||||
};
|
||||
public lineChartColors:Array<any> = [
|
||||
{ // grey
|
||||
@@ -46,10 +51,13 @@ export class LineChartComponent implements OnInit {
|
||||
.get()
|
||||
.subscribe(res => {
|
||||
console.log(res);
|
||||
|
||||
const newDataSet = [];
|
||||
const newLine = {data: res.data, label: res.label};
|
||||
const newLine = {data: res.lines.data, label: res.lines.label};
|
||||
newDataSet.push(newLine);
|
||||
this.lineChartData = newDataSet;
|
||||
|
||||
this.lineChartLabels = res.labels.data;
|
||||
});
|
||||
|
||||
console.log("Init");
|
||||
|
||||
@@ -4,6 +4,8 @@ import 'rxjs/add/operator/map'
|
||||
import { Http, Response, Headers } from '@angular/http';
|
||||
|
||||
import { LineData } from './line-data';
|
||||
import { GraphData } from './graph-data';
|
||||
import { LabelData } from './label-data';
|
||||
|
||||
@Injectable()
|
||||
export class DataService {
|
||||
@@ -11,7 +13,7 @@ export class DataService {
|
||||
|
||||
constructor(private http : Http){}
|
||||
|
||||
get(): Observable<LineData> {
|
||||
get(): Observable<GraphData> {
|
||||
console.log('Getting data');
|
||||
let lineChartData$ =
|
||||
//<LineData>( {data: [65, 59, 80, 81, 56, 55, 40], label: 'Series A'} );
|
||||
@@ -21,9 +23,7 @@ export class DataService {
|
||||
.map(mapData);
|
||||
|
||||
console.log(lineChartData$);
|
||||
|
||||
return lineChartData$;
|
||||
|
||||
}
|
||||
|
||||
private getHeaders(){
|
||||
@@ -33,15 +33,18 @@ export class DataService {
|
||||
}
|
||||
}
|
||||
|
||||
function mapData(response:Response): LineData {
|
||||
console.log('Mapping data', LineData);
|
||||
function mapData(response:Response): GraphData {
|
||||
console.log('Mapping data', GraphData);
|
||||
let nums = response.json().map(toData);
|
||||
let times = response.json().map(timeToData)
|
||||
|
||||
console.log(nums);
|
||||
|
||||
let line:LineData = <LineData>({data: nums, label: "Series A"});
|
||||
let label:LabelData = <LabelData>({data: times});
|
||||
console.log(line);
|
||||
return line;
|
||||
let graph:GraphData = <GraphData>({lines:line,labels:label});
|
||||
return graph;
|
||||
}
|
||||
|
||||
function toData(r:any){
|
||||
@@ -50,3 +53,9 @@ function toData(r:any){
|
||||
return num;
|
||||
}
|
||||
|
||||
function timeToData(r:any){
|
||||
let times = r.time;
|
||||
console.log('Parsed Time:', times);
|
||||
return times;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import { LineData } from './line-data';
|
||||
import { LabelData } from './label-data';
|
||||
|
||||
export class GraphData {
|
||||
public lines: LineData;
|
||||
public labels: LabelData;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export class LabelData {
|
||||
public data: string[];
|
||||
}
|
||||
Reference in New Issue
Block a user