Data for sun ray diagrams with d3.hierarchy using D3js v4

I am trying to get a sun ray chart using d3.hierarchy with d3js v4. I did the same as the example here. But since the data that I received as an array of objects, and not the same as in the example, I added a small function so that the data is the same as from the example. Below is the function

const arrayToObject = (array) =>
    array.reduce((obj, item) => {
        obj[item.name] = item
        return obj
}, {})

Here is the link to the script: https://jsfiddle.net/snt1/mbszu1u5/8/

Thank.

+4
source share
1 answer

I'm not sure if this is the answer (I think it is), or should I post this as a comment BUT here with your code:

d3.hierarchy() "" "" , partition(root).

https://bl.ocks.org/maybelinot/5552606564ef37b5de7e47ed2b7dc099, , d3.hierarchy() {name: "flare", children: Array[15]}

, data , : {name: "test", children: data}, .

FIDDLE . (, arrayToObject)

, .:)

+3

Source: https://habr.com/ru/post/1689340/


All Articles