屏幕截图显示了值以及沿辅助 x 轴的减号。我想摆脱它。如果我错了请纠正我。
下面是代码:
var app = angular.module('myApp', ['nvd3']);
app.controller('myCtrl', function($scope) {
$scope.options = {
chart: {
type: 'multiBarHorizontalChart',
height: 500,
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,
stacked: true,
xAxis: {
showMaxMin: false
},
yAxis: {
axisLabel: 'Values',
tickFormat: function(d){
return d3.format(',f')(d);
}
}
}
};
最佳答案
您需要调整yAxis
的tickFormat
:
yAxis: {
axisLabel: 'Values',
tickFormat: function(d){
return d3.format(',f')(Math.abs(d)); // Use Math.abs() to get the absolute value
}
}
这会将绝对刻度值传递给格式化程序,呈现所有不带减号的值。
关于d3.js - 从辅助 x 轴的负值中删除负号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33749777/