【问题标题】:To remove minus sign from the values on the secondary Y-axis (Nvd3 -Multibar Horizontal Chart)从辅助 Y 轴上的值中删除减号(Nvd3 -Multibar Horizo​​ntal Chart)
【发布时间】:2015-11-18 05:18:53
【问题描述】:

我想从辅助 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 轴上删除。请帮我解决这个问题。

【问题讨论】:

  • 你能提供一把小提琴吗?

标签: javascript angularjs d3.js graph nvd3.js


【解决方案1】:

您应该能够使用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 */
    },

};

【讨论】:

  • 谢谢。有效。有没有办法将原点与页面中心对齐??,因为较高的值使其向左侧移动。
  • @SharathS 居中对齐本身就是一个问题。你可以做类似var max = d3.max(chart.yAxis.scale().domain(), function(d) { return Math.abs(d); })); chart.yAxis.scale().domain([-max, max]); 的事情。如果您将其放在另一个问题中,我会将其发布为该问题的答案。
  • @SharathS 你为什么撤销对这个答案的接受?是不是错了,还是不能解决你的问题?
  • 对不起!也许是一些技术故障。答案很完美。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-01
  • 2013-06-18
相关资源
最近更新 更多