Built with blockbuilder.org
Last active
July 24, 2016 23:33
-
-
Save EmbraceLife/1c3a4786aea8bd91f8ce041c0dc20d15 to your computer and use it in GitHub Desktop.
d3.tsv usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: gpl-3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello | World | |
---|---|---|
42 | fish | |
58 | cat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
</style> | |
</head> | |
<body> | |
<script> | |
// d3.tsv(url/"fileName.tsv", callback) | |
d3.tsv("data.tsv", function(error, data) { | |
if (error) throw error; | |
console.log("example1: ", data, data[0].Hello, data[0].World); | |
}); | |
console.log("tsv(url, callback) is an alias tsv(url).get(callback)"); | |
d3.tsv("data.tsv").get(function(error, data) { | |
if (error) throw error; | |
console.log("example2: ", data, data[0].Hello, data[0].World); | |
}); | |
console.log("tsv(url, row, callback) observes the specified row conversion function"); | |
d3.tsv("data.tsv", function(d) { d.Hello = -d.Hello; d.World = d.World + ".d3"; return d; }, function(error, data) { | |
if (error) throw error; | |
console.log("example3", data, data[1].Hello, data[1].World); | |
}); | |
console.log("tsv(url, row, callback) is an alias for tsv(url).row(row).get(callback)"); | |
d3.tsv("data.tsv").row(function(d) { d.Hello = -d.Hello; return d; }).get(function(error, data) { | |
if (error) throw error; | |
console.log("example4", data); | |
}); | |
console.log("tsv(url).mimeType(type).get(callback) observes the specified mime type");// function(test) { | |
d3.tsv("data.tsv").mimeType("text/plain").get(function(error, data) { | |
if (error) throw error; | |
console.log("example5", data); | |
}); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment