2013-01-22 2 views
0

String1, String2, Int1, Int2 형식의 CSV 파일이 있습니다. 각 행을 int로 축을 D3 사용하여 산점도에 배치하고 싶습니다. 그래서 D3을 사용하여 CSV 데이터를 테이블로로드하는 방법을 알았지 만 CSV 열을 변수에 직접로드하지 않는 이유는 무엇입니까?자바 스크립트 변수에 csv의 한 열을로드하십시오.

D3 또는 jQuery를 사용하여 한 번에 CSV의 단일 열을로드하는 방법을 아는 사람이 있습니까? 아니면 더 나은 해결책이 있습니까?

+0

HTTP : // 유래 나는

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) { 

의 플로팅 코드를 싸는와 함께 마지막 두 줄을 교체해야합니다. com/questions/6453094/parse-and-access-remote-csv-with-javascript-only가 도움이 될 수도 있습니다 – Johan

+0

d3 shoudl이 csv를 줄로 표시합니다. 행 개체의 lection. 따라서 열을 분리하는 가장 간단한 방법은지도 또는 편리한 _.pluck을 [underscore.js] (http://underscorejs.org/)에서 사용하는 것입니다. – Superboggly

답변

0

먼저 D3을 사용하고 특히 D3을 사용하여 CSV 파일을로드하는 데 도움이되는 유용한 연습을 위해 Andrew Davis에게 thecodingtutorials.blogspot.com을 보내 주셔서 감사합니다.

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 열이 객체에서 속성처럼 취급 될 수 있다는 것이다.

.attr("cx", function(d) {return x(d["XColumnName"])} 
.attr("cy", function(d) {return y(d["YColumnName"])} 
.... 
관련 문제