Created
September 21, 2018 10:56
-
-
Save AbubakarSiddiq/f62618a37721b05d788c7cd117f7f41e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BookstoreService } from './../../services/bookstore.service'; | |
import { Component, OnInit, AfterViewInit } from '@angular/core'; | |
@Component({ | |
selector: 'app-pie-chart', | |
templateUrl: './pie-chart.component.html', | |
styleUrls: ['./pie-chart.component.css'], | |
providers: [BookstoreService] | |
}) | |
export class PieChartComponent implements OnInit { | |
books: any[] = []; | |
valueData: number[] = []; | |
labelData: any[] = []; | |
constructor(private _bookstoreService: BookstoreService) { | |
this.dataVal(); | |
} | |
dataVal() { | |
this._bookstoreService.getBookStoreGroup() | |
.subscribe(books => { | |
this.books = books; | |
let i = 0; | |
let j = 0; | |
for (i = 0; i < this.books.length; i++) { | |
this.labelData.push(this.books[i][j].publisherName.publisherName.toString()); | |
this.valueData.push(this.books[i].length); | |
} | |
}); | |
} | |
data = { | |
labels: [this.labelData], | |
datasets: [{ | |
data: this.valueData, | |
backgroundColor: [ | |
"#00FFFF", | |
"#E0FFFF", | |
"#00FFFF", | |
] | |
}] | |
} | |
ngOnInit() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment