我创建了一个热力图和一些迷你图,参考this example。在这个例子中,用户可以点击行和列的标签,但在我的情况下,我只保留了点击列标签的可能性。
那个例子对我的数据非常完美,只是我需要根据单选按钮的选择更新热力图。
第一个单选按钮允许您选择区域类型(A或B)。 第二组单选按钮允许您选择要显示的每日数据。 然而,数据是“不完整的”:并不是所有月份都有每日数据,只有四月和十二月。 因此,如果您选择四月或十二月单选按钮,则显示热力图上的每日数据,否则显示月度数据。
这个例子可以工作,但它非常原始,因为每次都会删除并重新创建热力图。
我发现这个示例可以更新热图,但我无法调整代码。 在示例中,数据仅更改数值而不更改“形状”。也就是说,标签的数量保持不变。在我的情况下,情况有点更复杂。
我用代码创建了Plunker.
那个例子对我的数据非常完美,只是我需要根据单选按钮的选择更新热力图。
第一个单选按钮允许您选择区域类型(A或B)。 第二组单选按钮允许您选择要显示的每日数据。 然而,数据是“不完整的”:并不是所有月份都有每日数据,只有四月和十二月。 因此,如果您选择四月或十二月单选按钮,则显示热力图上的每日数据,否则显示月度数据。
这个例子可以工作,但它非常原始,因为每次都会删除并重新创建热力图。
// Return to the initial order when the user clicks on the button
d3.select('#initialOrder').on('click', function() {
var trans = heat.transition().duration(1000);
var sortedYear = Array.from(Array(numYLabels).keys());
trans.selectAll('.cell')
.attr('y', function(d) {
var row = parseInt(d3.select(this).attr('data-r'));
return sortedYear.indexOf(row)*cellSize;
});
trans.selectAll('.rowLabel')
.attr('y', function(d, k) {
return sortedYear.indexOf(k) * cellSize;
});
sortedYear.forEach(function(d) {
d3.select('#data-svg-' + d).raise();
});
});
// Area radio button change selection
d3.selectAll('input[name=area-rb]').on('change', function() {
areaSelected = d3.select('input[name="area-rb"]:checked').property("value");
console.log('areaSelected:', areaSelected);
d3.select('#heatmapSvg').remove();
d3.selectAll('.data-svg').remove();
createHeatmap();
});
// Month radio button change selection
d3.selectAll('input[name=month-rb]').on('change', function() {
monthSelected = d3.select('input[name="month-rb"]:checked').property("value");
console.log('monthSelected:', monthSelected);
if(avaibleDayData.includes(monthSelected)) {
d3.select('#heatmapSvg').remove();
d3.selectAll('.data-svg').remove();
createHeatmap();
}
else {
monthSelected = 'nothing';
d3.select('#heatmapSvg').remove();
d3.selectAll('.data-svg').remove();
createHeatmap();
}
});
我发现这个示例可以更新热图,但我无法调整代码。 在示例中,数据仅更改数值而不更改“形状”。也就是说,标签的数量保持不变。在我的情况下,情况有点更复杂。
我用代码创建了Plunker.