gpt4 book ai didi

javascript - dc.js 图表使用带有单击事件的新组函数重绘

转载 作者:行者123 更新时间:2023-12-03 07:49:29 24 4
gpt4 key购买 nike

当其他图表库单击事件时,我尝试使用新组重绘 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 上的组,然后重新渲染。 (我认为在很多情况下重绘在这里不起作用。)

关于javascript - dc.js 图表使用带有单击事件的新组函数重绘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35059940/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com