D3 v4 - Accessing selection array and find corresponding element

前端 未结 1 460
轮回少年
轮回少年 2020-12-19 07:34

I\'m trying to get a constraint relaxing to work for my piechart. It is based on this example https://jsfiddle.net/thudfactor/HdwTH/ but the relaxing method used seems not t

1条回答
  •  天涯浪人
    2020-12-19 08:01

    In D3 4.0, selections are not arrays anymore. According to the API:

    Selections no longer subclass Array using prototype chain injection; they are now plain objects, improving performance.

    So, if you console.log(textLabels), you're gonna see something like this:

    {_groups: Array[1], _parents: Array[1]}
    

    Depending on exactly what are you selecting. From there, you can access your array using textLabels._groups, for instance.

    For having an array, you have to use selection.nodes(), which, according to the API:

    Returns an array of all (non-null) elements in this selection.

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