Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从csv文件解析d3.v5中的BC日期_Javascript_Date_D3.js - Fatal编程技术网

Javascript 从csv文件解析d3.v5中的BC日期

Javascript 从csv文件解析d3.v5中的BC日期,javascript,date,d3.js,Javascript,Date,D3.js,我将维基百科中显示世界历史上所有战争的表格转换为csv文件,用这些数据构建散点图 CSV格式: War,Deathrange,Geometricmean(Note 1),Date,Combatants,Location,Notes Conquests of Cyrus the Great,"100,000+","100,000",549 BC–530 BC,Persian Empire vs. various states,Middle East,"Number given is the sum

我将维基百科中显示世界历史上所有战争的表格转换为csv文件,用这些数据构建散点图

CSV格式:

War,Deathrange,Geometricmean(Note 1),Date,Combatants,Location,Notes
Conquests of Cyrus the Great,"100,000+","100,000",549 BC–530 BC,Persian Empire vs. various states,Middle East,"Number given is the sum of all deaths in battle recorded by writers during this time period, does not take into account civilian deaths, the actual number may be much greater."
Greco–Persian Wars,
我想得到X轴上“date”的第一个日期,例如“549”。圆点的半径应与战争的持续时间有关

问题 我不知道如何解析d.3中的“BC”日期

到目前为止我做到了: 我的方法是用正则表达式查找字符串中的数字

let dataset = await d3.csv("../wars.csv");
let dateNumber = dataset[0].Date.match(/\d+/g);
为了检查日期是否包含“BC”并将其转换为“减号”,我做了以下操作:

我不知道如何将此方法应用于所有日期,而不仅仅是[0]

我试过了

 const dates = d => d.Date.match(/\d+/g);
    console.log(dates);
控制台正在记录:

function dates()
但是没有日期,即使是在像“dates[1]”这样的索引中

那么如何以一种格式解析CSV中包含“BC”的日期,从而使d3时间功能能够在x轴上显示这些日期?

因为我对JS和d3非常陌生,所以我很欣赏有用的资源


最好的,谢谢你

广告日期是什么样子的?他们说的是“公元1066年”?在这种情况下,正则表达式需要类似于
/\d{1,4}(AD|BC)/
。AD日期是什么样子的?他们说的是“公元1066年”?在这种情况下,正则表达式需要类似于
/\d{1,4}(AD|BC)/
function dates()