如何在NDV3中设置条的自定义宽度离散条形图 [英] How to set custom width of bar in NDV3 Discreate bar chart
问题描述
我试图使用nvd3图表创建垂直条形图。
Am trying to build vertical bar chart using nvd3 charts.
问题:
如果图表有单个记录,条宽度达到图表的3/4宽度。
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?
推荐答案
如果您查看源代码在这里。您会看到矩形的宽度是根据 rangeBand a>。似乎没有办法通过库的API来设置矩形的宽度。
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.
这篇关于如何在NDV3中设置条的自定义宽度离散条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!