1

I have an object that looks like this,

{
    "1420165140": 172.52,
    "1420254360": 63.78,
    "1420341900": 141.55,
    "1420422480": 85.8,
    "1421035920": 86.07,
    "1422506820": 118.42
}

The keys are epoch time stamps. I would like to extract the max and min dates of the keys using something like this,

var  range = d3.extent(d, function(d){ return d.key });

I've tried casting +d.key to a number from a string.

Unfortunately, all I get back is [undefined, undefined]

How can I run d3.extent on object keys?

James
  • 20,957
  • 5
  • 26
  • 41
Colin
  • 930
  • 3
  • 19
  • 42

1 Answers1

2

You'll need to use it as

var range = d3.extent(Object.keys(d));

where d is your JSON object.

altocumulus
  • 21,179
  • 13
  • 61
  • 84
Taran J
  • 805
  • 6
  • 10