DC.js 图表重绘与点击事件的新组功能
dc.js chart redrawing with new group function with click event
当其他图表库单击事件时,我正在尝试使用新组重新绘制 dc.js 图表。但它不会重绘。
这是我的javascript代码:
var donemChart = dc.rowChart('div#donem'),
hospitalTypeChart = dc.rowChart('div#hospital_type'),
ckysHospitalClassChart = dc.rowChart('div#ckys_hospital_class'),
ckysHospitalTypeChart = dc.rowChart('div#ckys_hospital_type'),
hospitalHealthRegionChart = dc.rowChart('div#hospital_health_region'),
hospitalRoleChart = dc.rowChart('div#hospital_role'),
hospitalsChart = dc.rowChart('div#hospitals');
d3.json('tsim.json',function(data){
var ndx = crossfilter(data);
var all = ndx.groupAll();
//define crossfilter dimensions
var donemDim = ndx.dimension(function(d){ return d.DONEM}),
hospitalTypeDim = ndx.dimension(function(d){ return d.KURUM_TURU}),
ckysHospitalClassDim = ndx.dimension(function(d){ return d.CKYS_KURUM_TURU}),
ckysHospitalTypeDim = ndx.dimension(function(d){ return d.CKYS_KURUM_TIPI}),
hospitalHealthRegionDim = ndx.dimension(function(d){ return d.SAGLIK_BOLGESI}),
hospitalRoleDim = ndx.dimension(function(d){ return d.HASTANE_ROL}),
hospitalsDim = ndx.dimension(function(d){return d.HASTANE}) ;
var donemGroup = donemDim.group().reduceSum(function(d){return d.toplam_muayene_say}),
hospitalTypeGroup = hospitalTypeDim.group().reduceSum(function(d){return d.toplam_muayene_say}),
ckysHospitalClassGroup = ckysHospitalClassDim.group().reduceSum(function(d){return d.toplam_muayene_say}),
ckysHospitalTypeGroup = ckysHospitalTypeDim.group().reduceSum(function(d){return d.toplam_muayene_say}),
hospitalRoleGroup = hospitalRoleDim.group().reduceSum(function(d){return d.toplam_muayene_say}),
hospitalsGroup = hospitalsDim.group().reduceSum(function(d){return d.toplam_muayene_say}),
hospitalHealthRegionGroup = hospitalHealthRegionDim.group().reduceSum(function(d){return d.toplam_muayene_say});
donemChart
.width(400)
.height(300)
.margins({top: 0, left: 0, right: 0, bottom: 0})
.group(donemGroup)
.dimension(donemDim)
.ordinalColors(['#E89F00'])
.label(function (d) {
return d.key;
})
.title(function (d) {
return "";
})
.ordering(function(d) { return -d.value; })
.valueAccessor(function(p) { return p.value; })
.elasticX(true)
.xAxis().tickFormat();
hospitalTypeChart
.width(400)
.height(300)
.margins({top: 0, left: 0, right: 0, bottom: 0})
.group(hospitalTypeGroup)
.dimension(hospitalTypeDim)
.ordinalColors(['#E89F00'])
.label(function (d) {
return d.key;
})
.title(function (d) {
return d.value;
})
.ordering(function(d) { return -d.value; })
.valueAccessor(function(p) { return p.value; })
.elasticX(true)
.xAxis().tickFormat();
ckysHospitalClassChart
.width(400)
.height(300)
.margins({top: 0, left: 0, right: 0, bottom: 0})
.group(ckysHospitalClassGroup)
.dimension(ckysHospitalClassDim)
.ordinalColors(['#E89F00'])
.label(function (d) {
return d.key;
})
.title(function (d) {
return "";
})
.ordering(function(d) { return -d.value; })
.valueAccessor(function(p) { return p.value; })
.elasticX(true)
.xAxis().tickFormat();
ckysHospitalTypeChart
.width(400)
.height(500)
.margins({top: 0, left: 0, right: 0, bottom: 0})
.group(ckysHospitalTypeGroup)
.dimension(ckysHospitalTypeDim)
.ordinalColors(['#E89F00'])
.label(function (d) {
return d.key;
})
.title(function (d) {
return "";
})
.ordering(function(d) { return -d.value; })
.valueAccessor(function(p) { return p.value; })
.elasticX(true)
.xAxis().tickFormat();
hospitalHealthRegionChart
.width(400)
.height(500)
.margins({top: 0, left: 0, right: 0, bottom: 0})
.group(hospitalHealthRegionGroup)
.dimension(hospitalHealthRegionGroup)
.ordinalColors(['#E89F00'])
.label(function (d) {
return d.key;
})
.title(function (d) {
return "";
})
.ordering(function(d) { return -d.value; })
.valueAccessor(function(p) { return p.value; })
.elasticX(true)
.xAxis().tickFormat();
hospitalRoleChart
.width(400)
.height(500)
.margins({top: 0, left: 0, right: 0, bottom: 0})
.group(hospitalRoleGroup)
.dimension(hospitalRoleDim)
.ordinalColors(['#E89F00'])
.label(function (d) {
return d.key;
})
.title(function (d) {
return "";
})
.ordering(function(d) { return -d.value; })
.valueAccessor(function(p) { return p.value; })
.elasticX(true)
.xAxis().tickFormat();
hospitalsChart
.width(1000)
.height(25000)
.margins({top: 0, left: 0, right: 0, bottom: 0})
.group(hospitalsGroup)
.dimension(hospitalsDim)
.ordinalColors(['#E89F00'])
.label(function (d) {
return d.key;
})
.title(function (d) {
return "";
})
.ordering(function(d) { return -d.value; })
.valueAccessor(function(p) { return p.value; })
.elasticX(true)
.xAxis().tickFormat();
chart.addListener("clickGraphItem", function(event){
if(event.item.dataContext.d_type==1){
var donemGroup = donemDim.group().reduceSum(function(d){return d.toplam_muayene_say}),
hospitalTypeGroup = hospitalTypeDim.group().reduceSum(function(d){return d.toplam_muayene_say}),
ckysHospitalClassGroup = ckysHospitalClassDim.group().reduceSum(function(d){return d.toplam_muayene_say}),
ckysHospitalTypeGroup = ckysHospitalTypeDim.group().reduceSum(function(d){return d.toplam_muayene_say}),
hospitalRoleGroup = hospitalRoleDim.group().reduceSum(function(d){return d.toplam_muayene_say}),
hospitalsGroup = hospitalsDim.group().reduceSum(function(d){return d.toplam_muayene_say}),
hospitalHealthRegionGroup = hospitalHealthRegionDim.group().reduceSum(function(d){return d.toplam_muayene_say});
dc.redrawAll();
}else if(event.item.dataContext.d_type==2){
var donemGroup = donemDim.group().reduceSum(function(d){return d.toplam_A_grubu_ameliyat_say}),
hospitalTypeGroup = hospitalTypeDim.group().reduceSum(function(d){return d.toplam_A_grubu_ameliyat_say}),
ckysHospitalClassGroup = ckysHospitalClassDim.group().reduceSum(function(d){return d.toplam_A_grubu_ameliyat_say}),
ckysHospitalTypeGroup = ckysHospitalTypeDim.group().reduceSum(function(d){return d.toplam_A_grubu_ameliyat_say}),
hospitalRoleGroup = hospitalRoleDim.group().reduceSum(function(d){return d.toplam_A_grubu_ameliyat_say}),
hospitalsGroup = hospitalsDim.group().reduceSum(function(d){return d.toplam_A_grubu_ameliyat_say}),
hospitalHealthRegionGroup = hospitalHealthRegionDim.group().reduceSum(function(d){return d.toplam_A_grubu_ameliyat_say});
dc.redrawAll();
}
dc.redrawAll();
});
dc.renderAll();
});
单击图表时,我在图表侦听器函数中检查数据类型后获得数据类型。我正在用新组对维度进行分组。当它被记录时,会显示新的组,但它对重绘图表不起作用。
我能做什么这个问题?我们该如何解决这个问题?
谢谢
您刚刚将hospitalTypeGroup
变量的引用(例如)重新分配给了其他对象。但图表仍然保留对旧对象的引用。您必须使用 hospitalTypeChart.group(hospitalTypeGroup)
重置hospitalTypeChart
上的组,然后重新渲染。(我认为重绘在很多情况下都不起作用。
您需要提醒 dc.js 更改的组。
仅创建具有相同名称的新维度和组不会替换它们。您还需要为每个图表相应地调用.group()
。
此外,我不建议每次单击某些内容时都创建新组(或维度)。交叉过滤器将随着每个新组而变慢,因为它们都需要响应每个过滤器操作。相反,请提前创建组,并在单击处理程序中应用它们。
相关文章:
- 将事件附加到对象/数组
- javascript处理一个对象数组以获得一个新的对象数组
- 如何在javascript上向数组的对象添加新元素
- Javascript事件;在新选项卡中打开”;
- 如何基于数组值创建新实例
- 如果数组仍在执行,async.forEach()将运行我添加到数组中的新元素
- 算法:从数组(javascript/angular)中按当前日期获取上一个和下一个事件
- underline-js:将键对象与数组键对象进行比较,如果存在,则移除现有的添加新的
- 如何将新的键/值对元素添加到现有数组
- 在2D数组中动态推送新列
- 使用Jquery收集数组中的行ID,然后为新表查询这些值
- csv数据中的新数组
- 将Backbone.View重新注入DOM,保留事件而不是创建新事件
- 将jQuery事件函数应用于新的Knockout.js数组元素
- 键按下事件新值
- DC.js 图表重绘与点击事件的新组功能
- jquery full calendar:每次获取新事件时,从源初始化一个数组
- 如何在xmpp服务器中创建新组
- 在JQuery中迭代数组中的新事件监听器
- 事件和数组位置