0
var data = d3.csv.parse(d3.select('#someid').text());

<div id=someid>
    Time,Person_ID
    8/13/2015 17:08,771347186
    8/13/2015 17:09,770884821
    8/13/2015 17:09,784219886
    8/13/2015 17:10,771342437
</div>

how do I load the csv data? The rest of the code is done. I just want the data passed to the variable "data" to be exactly the same. How I do this?

Mi-Creativity
  • 9,554
  • 10
  • 38
  • 47
  • a) you have to put the data in a html element with the id 'someid' - then it's not an external data or b) you use d3.csv to access an external file via an AJAX call. see e.g.http://bl.ocks.org/ee2dev/de4a9e0010795ace76b8 – ee2Dev Feb 16 '16 at 07:17
  • @eeDev can I do something like this: var data = d3.csv.text("data.csv", function(d){ d3.csv.parse(d, function(result){ return result; }); }); – Chua Jinfa Feb 16 '16 at 07:32
  • Look at this explanation from mike bostock http://stackoverflow.com/questions/9491885/csv-to-array-in-d3-js – ee2Dev Feb 16 '16 at 07:39
  • @ee2Dev Yeah I tried, but there seem to be a problem with loading the data to the variable. but why can't the above equation work? I don't get it. – Chua Jinfa Feb 16 '16 at 08:09
  • So what do you want? Loading data from an external file directly into one variable is not possible. You have to handle the data within the function. – ee2Dev Feb 16 '16 at 08:13
  • @ee2Dev so you mean only if the data is entered in the html div then loading data directly from the variable is possible. Else, we have to handle data within the callback function? – Chua Jinfa Feb 16 '16 at 08:19
  • Yes. The reason is reading from a file is supported by AJAX functions where you process the data from within the function. – ee2Dev Feb 16 '16 at 12:33
  • thank you @ee2Dev, I managed to solve the problem! – Chua Jinfa Feb 17 '16 at 01:40

0 Answers0