-
Notifications
You must be signed in to change notification settings - Fork 0
/
parseCSV.html
41 lines (38 loc) · 1004 Bytes
/
parseCSV.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
</head>
<body>
<input type="file" onchange="loadFile()" />
<script>
//Prepare the browser for reading the csv file
var reader = new FileReader();
function loadFile() {
//Select the uploaded file
var file = document.querySelector('input[type=file]').files[0];
//when a file is uploaded, call parseFile to process the uploaded csv file
reader.addEventListener("load", parseFile, false);
//if a file was selected, attempt to read it as text
if (file) {
reader.readAsText(file);
}
}
var delimiter = "";
function parseFile(){
/* Use this to process each row
var data = d3.csvParse(cleanFile(reader.result), function(d){
return d;
});
*/
if(delimiter == ','){
var data = d3.csvParse(reader.result);
}else{
var data = d3.tsvParse(reader.result);
}
console.log(data);
}
</script>
</body>
</html>