How to set custom width of bar in NDV3 Discreate b

2019-04-23 05:02发布

Am trying to build vertical bar chart using nvd3 charts.

Problem : If chart has single record, bar width reaches 3/4 of the chart width.

Question : How to change width of the bars in Discrete bar chart?

Have attached chart please guide me..

enter image description here

2条回答
迷人小祖宗
2楼-- · 2019-04-23 05:30

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,
查看更多
The star\"
3楼-- · 2019-04-23 05:52

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. There doesn't appear to be a way to set the width of the rectangle though the library's 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.

查看更多
登录 后发表回答