-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathechart5.html
146 lines (141 loc) · 3.47 KB
/
echart5.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE html>
<html>
<meta charset="utf-8" />
<head>
<!-- Include the ECharts file you just downloaded -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/echarts.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/4.1.2/papaparse.min.js"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@200;300;400;500;600&display=swap" rel="stylesheet">
<style>
.chart {
height: 600px;
width: 100%;
}
</style>
</head>
<body>
<div class="chart" id="echarts-5"></div>
<script src="shared.js"></script>
<script>
function drawEChart5(data, title, headers) {
const dateList = data?.Date;
const myChart = echarts.init(document.getElementById("echarts-5"));
const series = [];
delete data?.Date;
headers?.forEach((h) => {
const _data = data?.[h];
series.push({
data: parseNumbers(_data),
type: "line",
name: h,
smooth: true,
smoothMonotone: "x",
symbol: "none",
symbolSize: 2,
lineStyle: {
width: 2.5,
},
emphasis: {
focus: "series",
},
});
});
const _media = JSON.parse(JSON.stringify(media));
_media[0].option.grid.bottom = '110';
_media[0].option.grid.left = '40';
const option = {
title: {
text: title,
...titleStyle,
},
color: [
"#DE2F8F",
"#12BC81",
"#254294",
"#0071C6",
"#F54A4A",
"#AF52C7",
],
textStyle,
xAxis: {
type: "category",
data: dateList,
name: "Age of Network in Years",
nameLocation: "middle",
nameGap: "40",
nameTextStyle: {
color: "#333",
},
axisTick: {
alignWithLabel: true,
},
},
tooltip: {
trigger: "axis",
confine: true
},
legend: {
data: headers,
...legendStyle,
},
calculable: true,
grid: {
show: true,
top: "70",
bottom: "90",
},
yAxis: {
type: "value",
name: "Inflationary Rewards Plus Emissions (in millions)",
nameLocation: "middle",
max: 1000000000,
nameGap: "80",
nameTextStyle: {
color: "#333",
},
nameTextStyle: {
fontSize: 14,
},
axisLabel: {
formatter: function (value, index) {
return (value / 1000000)?.toLocaleString();
},
},
},
series: series,
media: _media
};
myChart.setOption(option);
resizeChart(myChart);
}
// drawEChart5
$.get(googleSheetUrl + "694509505&single=true&output=csv", function (csvStr) {
// parse data using Papa Parse
let data = Papa.parse(csvStr, {
skipEmptyLines: true,
header: false,
})?.data;
const title = data?.[0]?.[0];
let headers = data?.[1];
data = data?.slice(2);
const array_data = [];
// prepapre data
headers?.forEach((h) => {
const index = headers?.findIndex((header) => header === h);
const _d = [];
data?.forEach((d) => {
_d.push(d[index]);
});
array_data[h || "Date"] = _d;
});
headers = headers?.slice(1)?.sort((a, b) => a?.localeCompare(b?.firstname));
// draw data
drawEChart5(array_data, title, headers);
});
</script>
</body>
</html>