d3.js - 从辅助 x 轴的负值中删除负号

标签 d3.js charts nvd3.js

屏幕截图显示了值以及沿辅助 x 轴的减号。我想摆脱它。如果我错了请纠正我。

Multibar-Horizontal Chart

下面是代码:

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);

                }
            }
        }

    };

最佳答案

您需要调整yAxistickFormat:

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/

相关文章:

rCharts rNVD3 工具提示自定义

d3.js - 我如何格式化d3图中显示的值

javascript - d3分组条形图创建问题

javascript - D3 两个圆环图相互叠加,不同的数据集。 JavaScript/HTML

javascript - Chart Js 使用下拉菜单更新数据集

python - Plotly:如何从两行数据绘制折线图?

javascript - 奇怪的标签/工具提示行为,nvd3 折线图

javascript - D3 - 如何正确标记 x 轴

d3.js - Cubism.js/d3.js 规模和范围

java - 在 JFreeChart 中制作自定义环形图