d3用逗号替换分号 [英] d3 replacing semicolon with comma

查看:87
本文介绍了d3用逗号替换分号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望一个比我聪明的人可以迅速帮助解决这个问题.我有带有分号分隔符的csv文件.它无法阅读标题:

Hoping someone way clever than me can quickly help solve this. I have csv files coming in with a semicolon seperator. it cant read the headings:

d3.csv("file.csv", function(error, data) {
   data.forEach(function(d) {
       d.date = parseDate(d.date);
       d.value2 = +d.value2;
       d.value1 = +d.value1;
   });

我尝试添加类似data.replace(/\ s *; \ s */g,,")之类的东西,但是不起作用.

I've tried adding something like data.replace(/\s*;\s*/g, ",") but doesnt work.

感谢帮助.

推荐答案

让我们将我的评论转换为答案,这样就不会无人问津:

Let's convert my comment to an answer, so it's not left unanswered:

假设您的值用分号分隔(因此从技术上讲,它不再是CSV),则可能需要查看以下内容: https://github.com/d3/d3-dsv

Assuming that your values are separated by a semicolon (so technically it's not a CSV anymore), you might want to look at this: https://github.com/d3/d3-dsv

这篇关于d3用逗号替换分号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆