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 badges2 Answers
Reset to default 3You 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
版权声明:本文标题:javascript - How to parse a local tsv variable on d3.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744988090a2636214.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论