Here's a pen:
http://codepen.io/cheapsteak/pen/MaYaNR
I'm loading the data via d3.select('#chart svg').datum(data)
The data is fetched from NPM's download stats API, and after transformation, ends up being in the format of
{
key: String
values: [{x: Date, y: Number}]
}
Data I get from the server:
{
"node-sass": {
"downloads": [
{
"day": "2015-05-20",
"downloads": 25307
}
]
}
}
My transformation function:
function processServerData(json) {
if (json.downloads && json.package) {
return {
key: json.package,
values: json.downloads.map( entry => { return {x: new Date(entry.day), y: entry.downloads}; })
};
} else {
return _.values(json).map(processServerData);
}
}
What I'm passing in:
{"day":"2015-05-24","downloads":11296}