最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to parse a local tsv variable on d3.js - Stack Overflow

programmeradmin2浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论