javascript - Want to show unique values only using d3.js not working -


i have large dataset same detector having multiple occurrence. there many detectors. want fill combobox unique detectors only. using following code:

d3.select("#detectors")     .selectall("option")     .data(d3.map(data, function(d) {             return d.code;         })         .keys())     .enter()     .append("option")     .text(function(d) {         return d;     }).attr("value", function(d) {         return d;     }); 

but not showing unique detector codes. rather combobox being filled number 1 ongoing. how can desired goal. sample simple dataset is

var data=[{"code":5222,"date":3-4-2015},{"code":5222,"date":3-6-2015},{"code":5222,"date":3-7-2015},]; 

the data has in real large number of detectors unique code. want show these unique codes in combobox. above case there 1 5222 in options

i think need use nest().

var nest = d3.nest()   .key(function(d) { return d.code; })   .entries(data); 

that create new array each code once , object of objects have value.

edit

var data=[{"code":5222,"date":3-4-2015},{"code":5222,"date":3-6-2015},{"code":5222,"date":3-7-2015}];  var nest = d3.nest()   .key(function(d) { return d.code;})   .entries(data);  d3.select("#detectors").selectall("option")   .data(nest)   .enter()     .append("option")     .text(function(d){ return d.key;})     .attr("value",function(d){return d.key;}); 

this code works me no errors


Popular posts from this blog