Skip to content

Instantly share code, notes, and snippets.

@desoga10
Last active March 22, 2023 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save desoga10/a933b3eb4b785e9df62f649cd849dcf4 to your computer and use it in GitHub Desktop.
Save desoga10/a933b3eb4b785e9df62f649cd849dcf4 to your computer and use it in GitHub Desktop.
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