【发布时间】:2015-07-16 08:15:17
【问题描述】:
所以我目前有这张图表,上面有 2 条线。一根蓝线,一根红线。我在蓝线上有一个功能,当点击它时,它会隐藏红线。但是我希望在页面加载时隐藏红线,然后当您单击蓝线时......它会显示红线。有人知道怎么做吗?
蓝线:
svg.append("path")
.attr("class", "line")
.attr("id", "blueLine")
.attr("d", valueline(data))
.on("click", function(){
// Determine if current line is visible
var active = redLine.active ? false : true ,
newOpacity = active ? 0 : 1;
// Hide or show the elements
d3.select("#redLine").style("opacity", newOpacity);
// Update whether or not the elements are active
redLine.active = active;
});
红线:
svg.append("path")
.attr("class", "line")
.style("stroke", "red")
.attr("id", "redLine")
.attr("d", valueline2(data));
【问题讨论】:
标签: javascript d3.js onclick line show-hide