質問編集履歴
1
コードとコンソールの画像を追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -15,3 +15,121 @@
|
|
15
15
|
|
16
16
|
|
17
17
|
原因がわかる方おられましたらご教授願います。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
追記
|
22
|
+
|
23
|
+
```
|
24
|
+
|
25
|
+
let label = [], num = [], place = []
|
26
|
+
|
27
|
+
let hiduke = new Date()
|
28
|
+
|
29
|
+
let num_Place
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
//定数の定義
|
34
|
+
|
35
|
+
const csvDirectory = "/public/src/csv_sunlight"
|
36
|
+
|
37
|
+
const filename = "20211206_sunlight.csv"
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
//CSVファイル読み込み
|
42
|
+
|
43
|
+
const req = new XMLHttpRequest()
|
44
|
+
|
45
|
+
req.open("GET", csvDirectory + "/" + filename)
|
46
|
+
|
47
|
+
req.send(null)
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
req.onload = () =>{
|
52
|
+
|
53
|
+
if(req.status != 404){
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
//CSVのデータを改行ごとに配列に格納
|
58
|
+
|
59
|
+
const line = req.responseText.split("\n")
|
60
|
+
|
61
|
+
const data = []
|
62
|
+
|
63
|
+
const len_Column = (line[2].match(/,/g)||[]).length + 1
|
64
|
+
|
65
|
+
num_Place = (len_Column - 1) / 2
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
//観測日付と日射量を二次元配列に格納
|
70
|
+
|
71
|
+
for(let i = 0; i < line.length - 1; i++){
|
72
|
+
|
73
|
+
const cells = line[i].split(",")
|
74
|
+
|
75
|
+
let posSlash = cells[0].lastIndexOf("/")
|
76
|
+
|
77
|
+
cells[0] = cells[0].substr(posSlash + 1)
|
78
|
+
|
79
|
+
data.push(cells)
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
//観測地点を配列に格納
|
86
|
+
|
87
|
+
for(let i = 1; i < len_Column; i += 3){
|
88
|
+
|
89
|
+
place.push(data[2][i])
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
//二次元配列を単元配列に分割
|
96
|
+
|
97
|
+
for(let i = 5; i < data.length - 1; i++){
|
98
|
+
|
99
|
+
label.push(data[i][0])
|
100
|
+
|
101
|
+
let k = 0
|
102
|
+
|
103
|
+
for(let j = 1; j < len_Column; j+=3){
|
104
|
+
|
105
|
+
if(num[k] === undefined){
|
106
|
+
|
107
|
+
num[k] = []
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
num[k].push(data[i][j])
|
112
|
+
|
113
|
+
k++
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
console.log(num)
|
124
|
+
|
125
|
+
console.log(num[0])
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
```
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
![イメージ説明](7923d13b8c36077cec846a662688a3f4.png)
|
134
|
+
|
135
|
+
![イメージ説明](0929bbde676ab0b3d6fc9b088d0588c2.png)
|