我正在尝试在其他图表库点击事件时使用新组重绘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();
});
当我点击图表监听器功能中的数据类型后点击图表我得到数据类型。我正在将维度与新组分组。当它是consol记录新组显示但它不会影响重绘图表
我该怎么办?我们怎样解决这个问题?
由于
答案 0 :(得分:1)
您刚刚将hospitalTypeGroup
变量(例如)的引用重新分配给其他对象。但图表仍然保留对旧对象的引用。您必须使用hospitalTypeChart
重置hospitalTypeChart.group(hospitalTypeGroup)
上的论坛,然后重新渲染。 (我不认为重绘会在很多情况下起作用。)
答案 1 :(得分:0)
您需要提醒已更改群组的dc.js.
仅创建具有相同名称的新维度和组不会替换它们。您还需要适当地为每个图表调用.group()
。
此外,我不建议每次点击某些内容时创建新的组(或维度)。 Crossfilter会因每个新组的速度而变慢,因为所有这些组都需要响应每个过滤器操作。相反,请提前创建组,并将它们应用于单击处理程序。