-
Notifications
You must be signed in to change notification settings - Fork 18
/
04-data-from-csv.html
45 lines (36 loc) · 1.3 KB
/
04-data-from-csv.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Data from CSV</title>
<script src="https://d3js.org/d3.v4.min.js"></script>
<style type="text/css">
/* Any CSS style rules can go here */
</style>
</head>
<body>
<script type="text/javascript">
//D3 can easily load in data from plain-text CSV or JSON files.
//NOTE: You must view this page as served by a local web server
// for this to work. Meaning, you must view the page in
// a web browser at http://localhost/...
var myData;
//Load data from CSV with d3.csv():
d3.csv("data/datafile.csv", function(data) {
//This callback function is run if and when the data file
//has been loaded successfully. So this would be a good
//place to put code that then parses the data further,
//copies it over to a variable, and/or renders the visualization.
//The parsed CSV is passed in as 'data', so here we hand
//it off to 'myData' for easy access later.
myData = data;
//Here we print 'myData' to the console, just to verify it loaded
console.log(myData);
});
//Load data from JSON in the same fashion, but with d3.json():
//d3.csv("datafile.json", function(data) {
// console.log(data);
//});
</script>
</body>
</html>