Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. import { Component, ViewChild } from '@angular/core';
  2. import { Chart } from 'chart.js';
  3.  
  4. @Component({
  5. selector: 'app-home',
  6. templateUrl: 'home.page.html',
  7. styleUrls: ['home.page.scss'],
  8. })
  9. export class HomePage {
  10. @ViewChild('barChart') barChart;
  11.  
  12. bars: any;
  13. colorArray: any;
  14. constructor() { }
  15.  
  16. ionViewDidEnter() {
  17. this.createBarChart();
  18. }
  19.  
  20. createBarChart() {
  21. this.bars = new Chart(this.barChart.nativeElement, {
  22. type: 'bar',
  23. data: {
  24. labels: ['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8'],
  25. datasets: [{
  26. label: 'Viewers in millions',
  27. data: [2.5, 3.8, 5, 6.9, 6.9, 7.5, 10, 17],
  28. backgroundColor: 'rgb(38, 194, 129)', // array should have same number of elements as number of dataset
  29. borderColor: 'rgb(38, 194, 129)',// array should have same number of elements as number of dataset
  30. borderWidth: 1
  31. }]
  32. },
  33. options: {
  34. scales: {
  35. yAxes: [{
  36. ticks: {
  37. beginAtZero: true
  38. }
  39. }]
  40. }
  41. }
  42. });
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement