Skip to content

Instantly share code, notes, and snippets.

@EmbraceLife
Last active July 24, 2016 23:33
Show Gist options
  • Save EmbraceLife/1c3a4786aea8bd91f8ce041c0dc20d15 to your computer and use it in GitHub Desktop.
Save EmbraceLife/1c3a4786aea8bd91f8ce041c0dc20d15 to your computer and use it in GitHub Desktop.
d3.tsv usage
license: gpl-3.0
Hello World
42 fish
58 cat
<!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