Created
May 9, 2014 12:13
-
-
Save FaKod/e6724675e4ebaf9f8fa4 to your computer and use it in GitHub Desktop.
D3.js 0 fill null values with d3 series data. See http://stackoverflow.com/a/17057231/436937
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function insertValues(data, value, dimension, metric, domain) { | |
var defaults = {}; | |
domain.forEach(function(item) { | |
var v = {}; | |
v[dimension] = item; | |
v[metric] = value; | |
defaults[item] = v; | |
}); | |
_.each(data, function(item) { | |
var vals = _.groupBy(item.values, function(i) { | |
return i[dimension]; | |
}); | |
vals = _.flatten(_.values(_.defaults(vals, defaults))); | |
vals = _.sortBy(vals, dimension); | |
item.values = vals; | |
}); | |
return data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment