dc.js
dc.js copied to clipboard
The chart will be redrawn after chart.resetSvg();
When I call chart.resetSvg() or
if($('#groupRowChart svg').length)
d3.select("#groupRowChart").select('svg').remove();.
it will redraw the chart after remove. It does remove the chart, after that it will draw it again.
`function drawGroupRowChart(data) {
initialiseGroupsRowChart();
data = jQuery.parseJSON(data);
groupsRowChart = dc.rowChart("#groupRowChart");
var ndx = crossfilter(data),
all = ndx.groupAll(),
groupsDim = ndx.dimension(function (d) { return d.name; }),
groupsGroup = groupsDim.group().reduceSum(function (d) {
return d.value;
});
groupsRowChart
.width(500)
.height(500)
.margins({ top: 20, left: 10, right: 10, bottom: 20 })
.dimension(groupsDim)
.group(groupsGroup)
.label(function (d) {
if (groupsRowChart.hasFilter() && !groupsRowChart.hasFilter(d.key)) {
return d.key + '(0%)';
}
var label = d.key;
if (all.value()) {
label += '(' + d.value + ')';
}
return label;
})
.title(function (d) { return d.name; })
.on('filtered.monitor', function (chart, filter) {
flterCallback(chart, filter, data);
})
.elasticX(true)
.rowsCap(10)
.ordering(function (d) { return -d.value })
.xAxis().ticks(5);
showGroupsRowChartTittle('<strong>Parent Group Row Chart</strong>');
dc.renderAll();
}`
`function initialiseGroupsRowChart() {
resetGroupsRowChart();
showGroupsRowChartTittle('');
if(groupsRowChart)
groupsRowChart.resetSvg();
// $("#groupRowChart").html("");
// if ($('#groupRowChart svg').length)
// d3.select("#groupRowChart").select('svg').remove();
}`
`function flterCallback(chart, filter, data){
if(filter){
getFilePath(filter, data);
showGroupRowChartSelect(filter);
chart.filterAll();
}
}`
resetSvg is an internal function. It does have the effect of clearing the chart from view but that's not its intended purpose - it's more a part of the render process.
The Javascript operates separately from the DOM so removing the svg is not enough. You're looking for dc.chartRegistry.deregister(chart). Then you can remove the DOM elements however you want.
Thank you very much it worked as magic.