Using an associative array as data for D3

前端 未结 2 728
慢半拍i
慢半拍i 2021-02-12 11:50

I have a very simple D3 example that first reads data into an associative array, then displays it in a bar graph.

I can\'t seem to get anything to display using this met

相关标签:
2条回答
  • 2021-02-12 12:27

    You can use the functions d3.values or d3.entries to work directly with associative arrays. You simply need to take it into account in the functions that set attributes (e.g. function(d) { return d.value; }).

    0 讨论(0)
  • 2021-02-12 12:37

    I found that in order for bar chart generation to work well, the following format works best. It's based on the the D3 post-parsed CSV format.

    var dataSet1 = [
      {xCoordinate: "Legend String 1", magnitude: 54, link: "http://www.if4it.com"},
      {xCoordinate: "Legend String 2", magnitude: 21, link: "http://www.if4it.com/glossary.html"},
      {xCoordinate: "Legend String 3", magnitude: 31, link: "http://www.if4it.com/resources.html"},
      {xCoordinate: "Legend String 4", magnitude: 14, link: "http://www.if4it.com/taxonomy.html"},
      {xCoordinate: "Legend String 5", magnitude: 19, link: "http://www.if4it.com/disciplines.html"},
      {xCoordinate: "Legend String 6", magnitude: 47, link: "http://www.if4it.com"},
      {xCoordinate: "Legend String 7", magnitude: 27, link: "http://www.if4it.com/glossary.html"}];
    

    The format allows for the correlation of coordinates, magnitudes, legends and html links to each other.

    A working example can be found at: http://bl.ocks.org/2164562.

    0 讨论(0)
提交回复
热议问题