我有一个用 制作的折线图d3,但由于数据的形状,线条和点(我在每个特定数据点的线条上使用点)通常最终彼此重叠。
为了解决这个问题,我结束0.4了对线条和点的不透明度,当你将鼠标悬停在一条线上时,这条特定数据线的线条和点会弹出,并将其不透明度设置为1。
我的问题是:我正在使用该.raise()功能使它们弹出并站在其余的线条和点上,该功能仅适用于我的线条选择而不适用于我的点选择,我不知道为什么。
我的代码:
// draw the data lines
const lines = svg.selectAll('.line')
.data(this.data)
.enter()
.append('path')
.attr('class', 'data.line')
.attr("fill", "none")
.attr("stroke", d => colors(d.key))
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("stroke-width", 2.5)
.attr('stroke-opacity', 0.4)
.attr('d', d => line(d.values))
.on('mouseenter', d => {
// Highlight them
let myCircles = circles.selectAll('.circle');
lines.attr('stroke-opacity', b => {
return b.key === d.key ? 1 : 0.4;
});
myCircles.attr('fill-opacity', b => {
return b[this.typeIdentifier] === d.key ? 1 : …Run Code Online (Sandbox Code Playgroud)