-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathechart1.html
131 lines (128 loc) · 3.1 KB
/
echart1.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
<!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-1"></div>
<script src="shared.js"></script>
<script>
function drawEChart1(data, title, headers) {
const dateList = data?.Date;
const myChart = echarts.init(document.getElementById("echarts-1"));
const series = [];
headers?.forEach((h) => {
const _data = data?.[h];
series.push({
data: parseNumbers(_data),
type: "line",
name: h,
smooth: true,
smoothMonotone: "x",
symbol: "none",
symbolSize: 2,
stack: "Total",
areaStyle: {
opacity: 0.5,
},
emphasis: {
focus: "series",
},
});
});
const _color = JSON.parse(JSON.stringify(color));
_color[0] = "#dfdf02";
const option = {
title: {
text: title,
...titleStyle,
},
textStyle,
color: _color,
xAxis: {
type: "category",
data: dateList?.map((date) => date?.replace(/\,/g,"-")),
axisTick: {
alignWithLabel: true,
},
},
tooltip: {
trigger: "axis",
confine: true
},
legend: {
data: headers,
bottom: "0",
itemGap: 15,
textStyle: {
fontSize: 12,
fontFamily: "sans-serif",
color: "#6e7079e8",
},
},
calculable: true,
grid: {
show: true,
top: "80",
bottom: "80",
},
yAxis: {
type: "value",
name: "Cumulative $STORE Tokens",
nameLocation: "middle",
nameGap: "80",
nameTextStyle: {
color: "#333",
},
nameTextStyle: {
fontSize: 14,
},
axisLabel,
},
series: series,
media
};
myChart.setOption(option);
resizeChart(myChart);
}
// drawEChart1
$.get(googleSheetUrl + "0&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] = _d;
});
headers = headers?.slice(1);
// draw data
drawEChart1(array_data, title, headers);
});
</script>
</body>
</html>