如何从数据中选择d3.js中的唯一值 [英] How to select unique values in d3.js from data

查看:142
本文介绍了如何从数据中选择d3.js中的唯一值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码使用d3.js填充我的Combobox

I am using the following code to populate my Combobox using d3.js

d3.csv("Results_New.txt", function(data) {
dataset=data;
d3.select("#road").selectAll("option")
.data(data).enter().append("option").text(function(d){return d.roadname;}).attr("value",function(d){return d.roadname;});
});

有不同的行具有相同的名称。组合框中填充了这些重复的名称。例如,在多行中,道路的名称是I-80。但在组合框中,我只想看到I-80一次。

There are different rows with the same name. The combobox is populating with these duplicate names. For example in multiple rows the name of the road is I-80.But in the combobox I want to see I-80 only once. How can I do that?

推荐答案

仅通过 d3.map

Filter your data retaining unique keys only by d3.map

d3.select("#road").selectAll("option")
    .data(d3.map(data, function(d){return d.roadname;}).keys())
    .enter()
    .append("option")
    .text(function(d){return d;})
    .attr("value",function(d){return d;});

这篇关于如何从数据中选择d3.js中的唯一值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆