Last active
March 22, 2023 14:27
-
-
Save desoga10/a933b3eb4b785e9df62f649cd849dcf4 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 { Component } from '@angular/core'; | |
import Chart from 'chart.js/auto'; | |
import { ChartService } from './service/chart.service'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.css'], | |
}) | |
export class AppComponent { | |
title = 'ng-chart'; | |
chart: any = []; | |
result: any; | |
coinPrice: any; | |
coinName: any; | |
constructor(private service: ChartService) {} | |
ngOnInit() { | |
this.service.cryptoData().subscribe((res) => { | |
this.result = res; | |
this.coinPrice = this.result.data.coins.map((coins: any) => coins.price); | |
this.coinName = this.result.data.coins.map((coins: any) => coins.name); | |
console.log(this.coinPrice); | |
console.log(this.coinName); | |
this.chart = new Chart('canvas', { | |
type: 'bar', | |
data: { | |
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'], | |
datasets: [ | |
{ | |
label: '# of Votes', | |
data: [12, 19, 3, 5, 2, 3], | |
borderWidth: 1, | |
}, | |
], | |
}, | |
options: { | |
scales: { | |
y: { | |
beginAtZero: true, | |
}, | |
}, | |
}, | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment