Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.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
Javascript Can d3.js circle';s半径是否由样式属性指定?_Javascript_Css_D3.js - Fatal编程技术网

Javascript Can d3.js circle';s半径是否由样式属性指定?

Javascript Can d3.js circle';s半径是否由样式属性指定?,javascript,css,d3.js,Javascript,Css,D3.js,这显示了d3.js样式属性如何用于改变圆的外观(填充颜色、笔划颜色、笔划宽度等) 我可以使用style属性设置d3.js圆的半径吗?可以。但是最好使用attr进行DOM值操作和style进行css svg.selectAll(".dot") .data(data) .enter().append("circle") .attr("class", "dot")

这显示了d3.js样式属性如何用于改变圆的外观(填充颜色、笔划颜色、笔划宽度等)


我可以使用style属性设置d3.js圆的半径吗?

可以。但是最好使用
attr
进行
DOM值操作
style
进行
css

             svg.selectAll(".dot")
                .data(data)
                .enter().append("circle")
                .attr("class", "dot")
                .style("r", 3)
                .attr("cx", function(d) {
                  return x(d.date);
                }
                )
                .attr("cy", function(d) {
                  return y(d.value);
                })
                .attr("stroke", function(d) {
                  return color(this.parentNode.__data__.name)
                })
                .attr("fill", function(d) {
                  return color(this.parentNode.__data__.name)
                })
使用
style
attr
虽然两者的工作方式相同,但可以查看DOM的
结构

使用
attr

`<circle class="dot" r="3" cx="0" cy="174.375" stroke="#1f77b4" fill="#1f77b4"></circle>`

是的,你可以。但是最好使用
attr
进行
DOM值操作
style
进行
css

             svg.selectAll(".dot")
                .data(data)
                .enter().append("circle")
                .attr("class", "dot")
                .style("r", 3)
                .attr("cx", function(d) {
                  return x(d.date);
                }
                )
                .attr("cy", function(d) {
                  return y(d.value);
                })
                .attr("stroke", function(d) {
                  return color(this.parentNode.__data__.name)
                })
                .attr("fill", function(d) {
                  return color(this.parentNode.__data__.name)
                })
使用
style
attr
虽然两者的工作方式相同,但可以查看DOM的
结构

使用
attr

`<circle class="dot" r="3" cx="0" cy="174.375" stroke="#1f77b4" fill="#1f77b4"></circle>`

可以将圆的半径设置为属性或样式

但是,如果您指定了一个
attr(“r”)
,但是您有一个css样式,例如
圆圈
{r:50;}
,样式表始终优先于 属性

但是,如果您切换到使用
样式(“r”)
,则 特定于元素的样式具有优先权,因为它更为特定,如 你会想到的

因此,您可以根据优先级使用这些

//圈1
d3.选择(“svg”)
.附加(“圆圈”)
.attr(“cx”,50)
.attr(“cy”,50)
.attr(“r”,10);//半径10作为属性
//圈2
d3.选择(“svg”)
.附加(“圆圈”)
.attr(“cx”,150)
.attr(“cy”,50)
.风格(“r”,10)//半径10作为内联样式
/*外部样式*/
圈{
填充:绿色;
r:50;
}

您可以将圆的半径设置为属性或样式

但是,如果您指定了一个
attr(“r”)
,但是您有一个css样式,例如
圆圈
{r:50;}
,样式表始终优先于 属性

但是,如果您切换到使用
样式(“r”)
,则 特定于元素的样式具有优先权,因为它更为特定,如 你会想到的

因此,您可以根据优先级使用这些

//圈1
d3.选择(“svg”)
.附加(“圆圈”)
.attr(“cx”,50)
.attr(“cy”,50)
.attr(“r”,10);//半径10作为属性
//圈2
d3.选择(“svg”)
.附加(“圆圈”)
.attr(“cx”,150)
.attr(“cy”,50)
.风格(“r”,10)//半径10作为内联样式
/*外部样式*/
圈{
填充:绿色;
r:50;
}