【发布时间】:2015-02-05 12:49:04
【问题描述】:
我有一个 CSV 数据集,我正在使用 dc.js(交叉过滤器)。
Date, Country 1,Country 2,Country 3,Country 4,Country 5,Country 6,Target country (...)
2014/12/11, USA, France, UAE, (...), Iraq
我要做的是绘制一个每个国家/地区一行的行图。 这是我今天的解决方案:
var countries = ndx.dimension(function(d) {
var list = [];
list.push(d["Country 1"]);
if (d["Country 2"]) {list.push(d["Country 2"]);};
if (d["Country 3"]) {list.push(d["Country 3"]);};
if (d["Country 4"]) {list.push(d["Country 4"]);};
if (d["Country 5"]) {list.push(d["Country 5"]);};
if (d["Country 6"]) {list.push(d["Country 6"]);};
return list;
});
var countriesGroup = countries.group().reduceSum(function(d) {
return d.totalNumberOfStrikes;
});;
countryChart
.width(400).height(500)
.group(countriesGroup)
.dimension(countries)
.ordering(function(d){ return -d.value });
但是,如您所见,它不会将 uniques 推送到 list 数组中。这会导致愚蠢的结果,因为 CSV 行中的每个国家/地区组合都会在列表中创建一个新项目。
我想要的是有一个包含每个独特国家的列表,然后在行图中绘制。
你能帮忙吗? 非常感谢!
【问题讨论】:
标签: csv dc.js crossfilter