-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (47 loc) · 1.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
async function getData() {
// Set the API endpoint URL
const API_ENDPOINT = "https://api.coingecko.com/api/v3/coins/markets?vs_currency=mxn&ids=ethereum%2Cbitcoin%2Cmaker%2Cpax-gold%2Ctether-gold%2Cwrapped-bitcoin%2Cstaked-ether%2C&order=market_cap_desc&per_page=100&page=1&sparkline=false";
// Send a GET request to the API endpoint
const response = await fetch(API_ENDPOINT);
// Get the response data as a JSON object
const data = await response.json();
return data;
}
// Function to create the chart
async function createChart() {
// Get the data from the API
const dato = await getData();
// Get the labels (x-axis) and data (y-axis) for the chart
const labels = dato.map((coin) => coin.name);
const chartData = dato.map((coin) => coin.current_price);
// Create the chart
const contexto = document.getElementById("chart");
const charts = new Chart(contexto, {
type: "doughnut",
data: {
labels: labels,
datasets: [
{
label: "Cryptocurrency Price (MXN)",
data: chartData,
backgroundColor: [
'rgb(54, 162, 235)',
'rgb(255, 205, 86)',
'rgb(102, 0, 0)',
'rgb(128,128,0)',
'rgb(32,178,170)',
'rgb(255,140,0)',
'rgb(128,0,128)',
],
},
],
},
options: {
responsive: true,
maintainAspectRatio: false,
},
});
}
// Call the createChart function when the page loads
// createChart();
export { createChart };