1
我正在尝试为我的热图可视化添加颜色选项。我在年初预定的颜色阵列,和我绘制矩形这样的:动态更改热图的色阶
plotChart.selectAll(".cell")
.data(data)
.enter().append("rect")
.attr("class", "cell")
.attr("x", function (d) { return x(d.timestamp); })
.attr("y", function (d) { return y(d.hour); })
.attr("width", function (d) { return x(d3.timeWeek.offset(d.timestamp, 1)) - x(d.timestamp); })
.attr("height", function (d) { return y(d.hour + 1) - y(d.hour); })
.attr("fill", function (d) { return colorScale(d.value); });
当我点击下拉菜单中的链接,我这样做:
$(".colorMenu").click(function (event) {
event.preventDefault();
// remove # from clicked link
var addressValue = $(this).attr("href").substring(1);
// get color scheme array
var newColorScheme = colorDict[addressValue];
// update color scale range
colorScale.range(newColorScheme);
// here I need to repaint with colors
});
我的色阶位数规模,所以我不能使用逆函数来查找每个矩形的值。我不想再次读取数据,因为这会是一个负担,所以如何更改矩形的填充颜色?