-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
69 lines (63 loc) · 2.29 KB
/
index.html
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
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>working with API</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.min.js"></script>
</head>
<body>
<canvas id="chart" width="800px" height="400px" ></canvas>
<script>
chartit();
async function chartit() {
const data = await getData();
const ctx = document.getElementById('chart').getContext('2d');
const myChart = new Chart(ctx, {
type: 'line',
data: {
labels: data.xs,
datasets: [{
label: 'Global-mean monthly, seasonal, and annual means in °C',
data: data.ys,
fill: 'false',
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderColor: 'rgba(255, 99, 132, 1)',
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
// Include a dollar sign in the ticks
callback: function (value, index, values) {
return value + '°' ;
}
}
}]
}
}
});
myChart.canvas.parentNode.style = '1000px';
}
async function getData() {
const xs = [];
const ys = [];
const response = await fetch('ZonAnn.Ts+dSST.csv');
const data = await response.text();
const table = data.split('\n').slice(1);
console.log("entering loop");
table.forEach(elt => {
const rows = elt.split(',');
const year = rows[0];
xs.push(year);
const temp = rows[1];
ys.push(parseFloat(temp) + 14);
console.log(year, temp);
});
return { xs, ys };
}
</script>
</body>