Skip to content Skip to sidebar Skip to footer

D3 Getting Values From Keys Using Array Of Objects

So I read in a csv file on Country GDP, and I filtered out unwanted columns and countries. Now I want to know how to extract the values from this array of objects and use them to c

Solution 1:

I would assemble my data so that you have 4 keys for each point:

{country:"Germany", indicator:"...",  year:2004, value:55}

rather than having keys for each year. Just post-process your csv call.

As you are doing that, determine the min/max years and the min/max values.

Next you build a year scale(x axis) using a domain of [minYear, maxYear]. Next build a value scale for the y-axis using a domain of [minValue, maxValue].

Solution 2:

D3 wants to consume arrays of objects with identical sets of keys. If you must, have pre-processing stage where you mogrify the data into something that looks like:

[
    { key:value, key2:value },
    { key:value, key2:value },
    { key:value, key2:value },
    { key:value, key2:value },
    { key:value, key2:value }
]

Otherwise you will be having a very terrible time with D3, as most of the functional programming features of the toolkit will not work at all for you.

Post a Comment for "D3 Getting Values From Keys Using Array Of Objects"