【问题标题】:How to make D3 line hidden from start?如何使 D3 线从一开始就隐藏?
【发布时间】: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


    【解决方案1】:

    你想隐藏红线首字母?

    svg.append("path")
    .attr("class", "line")
    .style("stroke", "red")
    .attr("id", "redLine")
    .attr("d", valueline2(data))
    .style('opacity', 0);
    

    只需添加

    .style('opacity', 0);
    

    不行吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-26
      • 2023-02-09
      • 1970-01-01
      • 2022-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多