我是D3的新手,并在Lynda课程“使用D3.js进行数据可视化”中学习它。以下代码无法更改所选元素的样式。这和教学练习完全一样。D3选择:.classed({})无效,.style({})
d3.selectAll('.item:nth-child(2)')
.classed({
'highlight': true,
'item': false,
'bigger': true})
但是,在我运行下面的代码后,它们按照需要工作。
d3.selectAll('.item:nth-child(2)')
.classed('highlight',true)
.classed('item', false)
.classed('bigger',true})
其余的类似乎在.classed和.style中使用({})很多。某些在线答案表明,问题源于D3的错误版本,其中.classed({})或.style({})不起作用。我该如何解决这个问题?以下是我的html和css代码。
HTML代码
D3 GraphicD3 Graphic
CSS代码
.highlight {
color: #C64C6F;
font-weight: 600;
}
.item {
padding-left: 30px;
}
.bigger {
font-size: 150%;
}
+0
的可能的复制[D3 V4 - 无法读取空的属性text(http://stackoverflow.com/questions/38684597/d3-v4-cannot-read -property-text-of-null) –