csv data to nested json tree in d3

前端 未结 1 773
遥遥无期
遥遥无期 2021-01-23 07:55

I have a csv data file which looks like this

root,y,i,5
root,c,b,a,7
root,c,b,z,2

I\'d like to generate something similar to the flare.json data file like

相关标签:
1条回答
  • 2021-01-23 08:20

    I would use the d3 nest function to accomplish this. You can find documentation on how to use it here: http://bl.ocks.org/phoebebright/raw/3176159/

    The solution would look something like this:

    var nested_data = d3.nest()
      .key(function(d) { return d[0]; })
      .key(function(d) { return d[1]; })
      .entries(csv_data);
    
    0 讨论(0)
提交回复
热议问题