我有一个格式为String1,String2,Int1,Int2的CSV文件。我想把每一行放在一个散点图上,使用D3,以int为轴。所以我想出了如何使用D3将CSV数据加载到表中,但是后来我意识到,为什么不直接将CSV列加载到变量中呢?
那么,有人知道如何使用D3或jQuery一次加载CSV的一列吗?或者更好的是,有没有我应该考虑的更好的解决方案?
发布于 2013-01-23 14:22:52
首先,感谢thecodingtutorials.blogspot.com的Andrew Davis介绍了如何使用D3,尤其是如何使用D3加载CSV文件。
D3教程:http://www.thecodingtutorials.blogspot.com/2012/07/introduction-to-d3.html
加载CSV:http://thecodingtutorials.blogspot.com/2012/07/using-csv-and-text-files-with-d3.html
多列CSV:http://thecodingtutorials.blogspot.com/2012/08/using-multi-column-data-with-d3-part-1.html
总之,简而言之,CSV列可以被视为对象中的属性。
以前我在哪里
var vis = d3.select("#tryHere").append("svg:svg").attr("width", w).attr("height", h);
vis.selectall("circle")
.data(data).enter().append("svg:circle")
.attr("cx", function(d) { return x(d.x) })
.attr("cy", function(d) { return y(d.y) })
....
我需要把绘图代码放在
d3.csv("MyFile.csv", function(rawData) {
并将最后两行替换为:
.attr("cx", function(d) {return x(d["XColumnName"] )}
.attr("cy", function(d) {return y(d["YColumnName"] )}
....
https://stackoverflow.com/questions/14465930
复制相似问题