gnuplot
中常用的数据文件通常属于这种类型:
# This is my input
###a b c d ---etc---
a030067o.fits 2457542.734730 60.00 1.2690 -0.174 0.003 9.871737
a030068o.fits ???????????? 60.00 1.2650 -1.197 1.682 9.869020
a030069o.fits 2457542.736397 60.00 1.2610 -1.320 -0.429 9.865766
a030070o.fits 2457542.737242 60.00 1.2570 -0.503 -0.192 9.867632
a030071o.fits 2457542.738075 60.00 1.2530 0.370 0.424 9.868780
a030072o.fits 2457542.738920 60.00 1.2490 -0.000 -0.003 9.869078
a030073o.fits 2457542.739753 60.00 1.2450 -1.491 0.117 9.868382
# Third Dataset
a030074o.fits 2457542.740598 60.00 1.2410 -1.413 0.811 9.867624
a030075o.fits 2457542.741432 60.00 1.2370 0.363 1.411 9.866734
a030076o.fits 2457542.742277 60.00 1.2340 -0.868 -0.115 9.861761
a030077o.fits 2457542.743110 60.00 1.2300 -0.411 0.206 9.865149
基本上,
???
)字段; 这在科学中很常见,gnuplot
非常常用。
不幸的是,如果我想使用d3.js
生成基于网络的图表
如果它只有一个像那样的标题行
###a b c d e f
我可以用
解析它d3.text("file.dat", function (error,data){
data=data.replace(/[ \t\r]+/g,',');
var data = d3.csvParse(data)
});
但如果没有标题行,我就无法使用它。
这两种方式都不起作用(read csv/tsv with no header line in D3):
data=data.replace(/[ \t\r]+/g,',');
data = d3.csvParseRows(data).map(function(row) {
return row.map(function(value) {
return +value;
});
});
这不是(D3: ignore certain row in .csv):
d3.request("pianeta-ascii.dat").get(function (error,request) {
var dirtyCSV = request.responseText; \s+(?=\s)
dirtyCSV=dirtyCSV.replace(/\s/g,',');
var cleanCSV = dirtyCSV.split('\n').slice(1).join('\n');
var data = d3.csvParseRows(cleanCSV);
});
如何让它能够跳过评论和分离数据组?
我至少想要
的javascript版本 cat file.dat | grep -v "\#" |sed '/^\s*$/d' |awk '{print $1","$2","$3","$4","$5}'
并且,如果可能的话,可以在d3