如何在nvd3图表中添加边距

3

那行不通。SVG 样式不理解 margin-top 和 margin-bottom。看起来该库默认不支持在条形之间添加 padding。如果你想要添加,可能需要在这里添加:https://github.com/novus/nvd3/blob/master/src/models/multiBarHorizontal.js#L160 - WolfgangCodes
2个回答

8

0

根据您的需要自定义图表选项。您可以像下面所示添加边距到图表选项中。

 $scope.options = {
            chart: {
                type: 'multiBarHorizontalChart',
                height: 450,
                margin : {
                    top: 20,
                    right: 20,
                    bottom: 40,
                    left: 55
                },
                x: function(d){return d.label;},
                y: function(d){return d.value;},
                //yErr: function(d){ return [-Math.abs(d.value * Math.random() * 0.3), Math.abs(d.value * Math.random() * 0.3)] },
                showControls: true,
                showValues: true,
                duration: 500,
                xAxis: {
                    showMaxMin: false
                },
                yAxis: {
                    axisLabel: 'Values',
                    tickFormat: function(d){
                        return d3.format(',.2f')(d);
                    }
                }
            }
        };

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接