this part of a script to draw a d3 chart works:
var data = [
{"day":1,"Dollars":392262,"Pesos":22122},{"day":2,"Dollars":402544,"Pesos":22157},
etc.
];
//code, then
x.domain(data.map(function (d) { return d.day; }));
As long as the word "day" appears in the last line, no problem. However, it's not always "day." It might be "hour" or it might be "month." So I don't want any word hard coded in, I want a variable in its place; that variable would tell whether it's day or hour or month.
So I tried the following, which doesn't work:
var data = [
{"day":1,"Dollars":392262,"Pesos":22122},{"day":2,"Dollars":402544,"Pesos":22157},
etc.
];
key = Object.keys(data[0]);
period_grain = key[0]; //alerts 'day' (no quotes)
//code, then
x.domain(data.map(function (d) { return d.period_grain; }));
Obviously it's the way I'm using period_grain
but after research I still can't figure out how to use it properly.
Any idea how I can do it?