-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
91 lines (79 loc) · 2.4 KB
/
Copy pathmain.js
File metadata and controls
91 lines (79 loc) · 2.4 KB
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
function downloadWorkbook() {
let workbook = new exceljs.Workbook();
const imageSheet = workbook.addWorksheet("ImageSheet");
const dataSheet = workbook.addWorksheet("DataSheet");
rawDate.forEach((item, index) => {
dataSheet.getColumn(index + 1).values = [item.header, ...item.data];
});
let promise = [];
document.querySelectorAll(".plot-container").forEach((item, index) => {
promise.push(
html2canvas(item).then((c) => {
let image = c.toDataURL();
const imageId2 = workbook.addImage({
base64: image,
extension: "png",
});
imageSheet.addImage(imageId2, position[index]);
})
);
});
Promise.all(promise).then(() => {
workbook.xlsx.writeBuffer().then((b) => {
let a = new Blob([b]);
let url = window.URL.createObjectURL(a);
let elem = document.createElement("a");
elem.href = url;
elem.download = `${new Date().toString().replaceAll(" ", "")}.xlsx`;
document.body.appendChild(elem);
elem.style = "display: none";
elem.click();
elem.remove();
});
});
return workbook;
}
createChart("chart01");
createChart("chart02");
createChart("chart03");
function createChart(id) {
let elem = document.getElementById(id);
if (elem) {
Plotly.newPlot(
elem,
[
{
x: [1, 2, 3, 4],
y: [10, 15, 13, 17],
type: "scatter",
},
{
x: [1, 2, 3, 4],
y: [16, 5, 11, 9],
type: "scatter",
},
],
{ title: id }
);
}
}
let position = [
{
tl: { col: 1.5, row: 1.5 },
br: { col: 3, row: 3 },
},
{
tl: { col: 3, row: 3 },
br: { col: 6, row: 6 },
},
{
tl: { col: 6, row: 6 },
br: { col: 9, row: 9 },
},
];
let rawDate = [
{ header: "시도", data: ["서울", "서울", "서울", "서울", "서울", "서울", "서울", "서울", "서울", "서울"] },
{ header: "시군구", data: ["송파구", "송파구", "송파구", "송파구", "송파구", "송파구", "송파구", "서초구", "서초구", "서초구"] },
{ header: "사고유형", data: ["측면충돌", "추돌", "기타", "전도전복", "공작물충돌", "주/정차차량 충돌", "기타", "횡단중", "차도통행중", "길가장자리구역통행중"] },
];
if (document.getElementById("download")) document.getElementById("download").addEventListener("click", downloadWorkbook);