我有一个数据集,其中包含5列->国家,id,价值和部门。我能够使用值和国家在dc.js中创建一个行图,其中国家是我的维度。
var rowChart = dc.rowChart('#rowChart');
d3.csv('data.csv', function(data){
data.forEach(function(d){
d.country = d.country;
d.id = d.id;
d.value = +d.value;
d.sector = d.sector;
});
var height = 300;
var width = 300;
var ndx = crossfilter(data)
var countryDim = data.dimension(function (d) {
return d.country;
});
var countryGroup = countryDim.group().reduceSum(function (d) {
return d.value
})
rowChart
.width(300)
.height(900)
.margins({top: 10, right: 10, bottom: -1, left: 30})
.dimension(countryDim)
.group(countryGroup)
.colors('#86BC25')
.ordering(function (d) { return -d.value; })
.elasticX(true)
.xAxis();
rowChart
.title(function (d) { return d.value;})
.renderTitleLabel(true)
.titleLabelOffsetX(10);
dc.renderAll();
});这是我在csv中的数据
country,id,value,sector
USA,0982,10,high
AUS,0983,9,high
IND,0982,10,high
CHN,0982,8,high
CUB,0986,5,middle
FIN,0987,low我尝试创建一个jsfiddle,但似乎不起作用,对不起,我的第一次http://jsfiddle.net/i8rice/2r76bjt7/4/
我希望能够创建两个带有复选框的下拉列表。一个按国家/地区筛选行图表,另一个按行业筛选行图表。因此,如果我首先在下拉菜单中按“高”过滤扇区,那么行图将被过滤,而另一个下拉菜单应该只显示5个“高”国家。
我知道这是可以使用dc.selectMenu实现的,但我想要下拉复选框风格。我想知道dc.js是否可以做到这一点?
对不起,我是个新手,在d3.js、dc.js和crossfilter中提问。
发布于 2017-01-20 22:04:57
多亏了戈登,下拉菜单中的复选框才能正常工作。然而,在与其他一些人讨论后,他们建议复选框一旦勾选,就不会调用事件处理程序,因此编写了以下内容,这与dc.js中的内容几乎相同
selectField.on('postRender', function() {
$('#menuselect select').change(function(){
console.log($(this).val())
if ($(this).val() && $(this).val() != "") {
selectField.replaceFilter([$(this).val()]);
} else {
selectField.filterAll();
}
dc.events.trigger(function () {
dc.redrawAll();
});
}).multipleSelect({ placeholder: "Select Country"})
});一切正常,好吧,在本地测试。我不知道有什么其他的方法,因为我还是个新手。
https://stackoverflow.com/questions/41718707
复制相似问题