Guest User

Untitled

a guest
Sep 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import { BookstoreService } from './../../services/bookstore.service';
  2. import { Component, OnInit, AfterViewInit } from '@angular/core';
  3.  
  4. @Component({
  5. selector: 'app-pie-chart',
  6. templateUrl: './pie-chart.component.html',
  7. styleUrls: ['./pie-chart.component.css'],
  8. providers: [BookstoreService]
  9. })
  10. export class PieChartComponent implements OnInit {
  11.  
  12. books: any[] = [];
  13. valueData: number[] = [];
  14. labelData: any[] = [];
  15.  
  16. constructor(private _bookstoreService: BookstoreService) {
  17. this.dataVal();
  18. }
  19.  
  20. dataVal() {
  21. this._bookstoreService.getBookStoreGroup()
  22. .subscribe(books => {
  23. this.books = books;
  24. let i = 0;
  25. let j = 0;
  26. for (i = 0; i < this.books.length; i++) {
  27. this.labelData.push(this.books[i][j].publisherName.publisherName.toString());
  28. this.valueData.push(this.books[i].length);
  29. }
  30. });
  31. }
  32.  
  33. data = {
  34. labels: [this.labelData],
  35. datasets: [{
  36. data: this.valueData,
  37. backgroundColor: [
  38. "#00FFFF",
  39. "#E0FFFF",
  40. "#00FFFF",
  41. ]
  42. }]
  43. }
  44. ngOnInit() {
  45. }
  46. }
Add Comment
Please, Sign In to add comment