Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css d3.select.attr仅在从悬停操作调用时使用某些属性_Css_D3.js - Fatal编程技术网

Css d3.select.attr仅在从悬停操作调用时使用某些属性

Css d3.select.attr仅在从悬停操作调用时使用某些属性,css,d3.js,Css,D3.js,当我将鼠标悬停在一个表行上时,我正试图使一个动作起作用。我想要的是表格行变为灰色,对应于该表格行的图表笔划变为红色,宽度为5,每隔一笔划变为灰色 以下是代码片段: var paths = d3.selectAll("path"); var rows = tbody.selectAll("tr") .data(data) .enter() .append("tr") .on("mouseover", function(d,i) { d3.selec

当我将鼠标悬停在一个表行上时,我正试图使一个动作起作用。我想要的是表格行变为灰色,对应于该表格行的图表笔划变为红色,宽度为5,每隔一笔划变为灰色

以下是代码片段:

var paths = d3.selectAll("path");

var rows = tbody.selectAll("tr")
    .data(data)
    .enter()
    .append("tr")
    .on("mouseover", function(d,i) {
        d3.select(this)
        .style("background-color","gray");

        //this works
        d3.select(paths[0][i]).attr("stroke-width", 5);

        //this sets them all to gray
        d3.selectAll("path").attr("stroke", "gray");

        //this doesn't work???
        d3.select(paths[0][i]).attr("stroke", "red");

     });
我的想法是先把它们全部变成灰色,然后把单个的变成红色。出于某种原因,仅在其中一条路径上更改笔划属性不起作用,但在所有路径上更改笔划属性起作用,而仅在其中一条路径上更改笔划宽度属性起作用

我做错什么了吗

尝试使用
.style()
而不是
.attr()


不要使用
attr
试试
style
完美!谢谢为什么selectall使用attr?我把它作为答案贴了出来。请检查一下这个。
 d3.select(paths[0][i]).style("stroke", "red");