javascript - 从辅助 Y 轴上的值中删除负号(Nvd3 - 多条水平图表)

标签 javascript angularjs d3.js graph nvd3.js

我想去掉辅助 y 轴值中的负号。 下面的图表显示了相同的情况。 Nvd3 Multibar-Horizontal Chart

代码:

var app = angular.module('myApp', ['nvd3']);
app.controller('myCtrl', function($scope) {


    $scope.options = {
        chart: {
            type: 'multiBarHorizontalChart',
            height: 350,
            x: function(d){
                console.log(d.value);
                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

            },
            axisLabelDistance:50,
            yAxis: {
                axisLabel: 'Values',
                tickFormat: function(d){
                    return d3.format(',f')(Math.abs(d));
                }
            },
            valueFormat:d3.format(".0f"),

        },

    };

我已经删除了 x 轴值的减号,但机器人能够将其从辅助 y 轴删除。请帮助我解决这个问题。

最佳答案

您应该能够使用 valueFormat 属性设置条形值的格式,与 yAxis 的刻度值非常相似:

$scope.options = {
    chart: {
        /* more lines omitted for brevity */

        yAxis: {
            axisLabel: 'Values',
            tickFormat: function(d){
                return d3.format(',f')(Math.abs(d));
            }
        },
        valueFormat: function(d){
                return d3.format(',f')(Math.abs(d));
        },

        /* more lines omitted for brevity */
    },

};

关于javascript - 从辅助 Y 轴上的值中删除负号(Nvd3 - 多条水平图表),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33772342/

相关文章:

javascript - 计算句子长度和每个句子的平均单词数? | JavaScript

Javascript - 将整数写入文本脚本的字符串

javascript - AngularJS 在事件中返回一个 promise

html - 在ionic中设置默认 View

javascript - 关闭循环引用?

javascript - n%7 是什么意思?

javascript - 在 AngularJS 中使用 ng-jsoneditor 的 JSON 奇怪 View

javascript - D3 条形图上文本标签的定位

javascript - 如何给NVD3图添加标签换行功能?

javascript - 根据来自输入的百分比值为气泡分配颜色