Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试使用 nvd3 图表构建垂直条形图。
问题:如果图表有单条记录,条形宽度达到图表宽度的 3/4。
问题:如何更改离散条形图中条形的宽度?
附上图表请指导我..
如果您在这里查看源代码。您会看到矩形的宽度是根据使用rangeBand的项目数计算的。似乎没有办法通过库的 API 设置矩形的宽度。
如果您不想修补库,您可以使用零数据创建额外的假条,并提供一个标签格式化程序,如果值为零,它将返回一个空字符串,但假定零不是数据集中的有效数字.
使用以下代码设置宽度
dispatch: { renderEnd: function (e) { d3.selectAll("rect.nv-bar").attr('rx', 4).attr('ry', 4).attr('width', 15) } }
或者你可以使用
groupSpacing : 0.57,