简体   繁体   English

如何在NDV3 Discreate条形图中设置条形的自定义宽度

[英]How to set custom width of bar in NDV3 Discreate bar chart

Am trying to build vertical bar chart using nvd3 charts. 我试图使用nvd3图表构建垂直条形图。

Problem : If chart has single record, bar width reaches 3/4 of the chart width. 问题:如果图表有单个记录,则条形宽度达到图表宽度的3/4。

Question : How to change width of the bars in Discrete bar chart? 问题:如何更改离散条形图中条形的宽度?

Have attached chart please guide me.. 附图表请指导我..

在此输入图像描述

If you look at the source here . 如果你看一下这里的来源。 You'll see that the width of the rectangle is calculated based on the number of items using rangeBand . 您将看到矩形的宽度是根据使用rangeBand的项目数计算的。 There doesn't appear to be a way to set the width of the rectangle though the library's API. 似乎没有办法通过库的API设置矩形的宽度。

If you didn't want to patch the library, you could create additional fake bars with zero data and provide a label formatter that would return an empty string if the value was zero, but that assumes zero is not a valid number in your data set. 如果您不想修补库,则可以创建零数据的其他假条,并提供标签格式化程序,如果值为零则返回空字符串,但假定为零则不是数据集中的有效数字。

Use the follwing code to set the width 使用以下代码设置宽度

dispatch: {
    renderEnd: function (e) {
        d3.selectAll("rect.nv-bar").attr('rx', 4).attr('ry', 4).attr('width', 15)
    }
}

or you can use 或者你可以使用

groupSpacing : 0.57,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM