admin管理员组

文章数量:1406911

I currently have the following:

d3.tsv(filename, function(error, data) {
    data.forEach(function(d) {
        d.date = parseDate(d.date);
        d.outside = +d.outside;
        d.house = +d.house;
});

That gets a tsv file and processes it with no issues. What I would like to do is to replace "filename" (which is a file) with a variable (such a string containing text in tsv format). How can I easily do this? Thanks!

I currently have the following:

d3.tsv(filename, function(error, data) {
    data.forEach(function(d) {
        d.date = parseDate(d.date);
        d.outside = +d.outside;
        d.house = +d.house;
});

That gets a tsv file and processes it with no issues. What I would like to do is to replace "filename" (which is a file) with a variable (such a string containing text in tsv format). How can I easily do this? Thanks!

Share Improve this question asked Mar 28, 2014 at 18:14 Ismael ArenzanaIsmael Arenzana 932 silver badges6 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

You can use d3.tsv.parse() for this, e.g.

var data = d3.tsv.parse(string);

Actually, for example, you can obtain the string from a fetch query and then transform it to text so that later can be parsed with D3.js.

This is once loaded in your browser: https://d3js/d3.v5.min.js

var data = await fetch('/mytsv.tsv');
var mytsvstr = await data.text();
var tsvdata = await d3.tsvParse(mytsvstr);

Source: https://www.tutorialspoint./d3js/d3js_delimiterseparated_values_api.htm

本文标签: javascriptHow to parse a local tsv variable on d3jsStack Overflow