-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
75 lines (68 loc) · 1.82 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
70
71
72
73
74
75
<!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>Chart.js project</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<canvas id="myChart" width="800" height="400"></canvas>
<script>
//Chart.js script
chartIt();
async function chartIt() {
const data = await getData();
const ctx = document.getElementById('myChart').getContext('2d');
const myChart = new Chart(ctx, {
type: 'line',
data: {
labels: data.xs,
datasets: [{
label: 'Combined Land-Surface Air and Sea-Surface Water Temperature in C°',
data: data.ys,
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
],
borderColor: [
'rgba(255, 99, 132, 1)',
],
borderWidth: 1
}]
},
options: {
scales: {
y: {
ticks: {
// Include a dollar sign in the ticks
callback: function(value, index, ticks) {
return value + '°';
}
}
}
}
}
});
}
// Data from CSV file
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);
table.forEach(row => {
const columns = row.split(',');
const year = columns[0];
xs.push(year);
const temp = columns[1];
ys.push(parseFloat(temp) + 14);
console.log(year, temp);
});
return {xs, ys };
}
</script>
</body>
</html>