【问题标题】:Angular nvd3 multibarchart stacked not showing properly角度 nvd3 多条形图堆叠未正确显示
【发布时间】:2016-05-14 01:48:34
【问题描述】:

我正在使用 angular nvd3 创建多条形图。它以分组格式正确显示数据,但单击堆叠时仅显示单色。 我为它创建了一个 plunker。任何想法我做错了什么?

  $scope.options = {
        chart: {
            type: 'multiBarChart',
            height: 450,
            margin : {
                top: 20,
                right: 20,
                bottom: 45,
                left: 45
            },
            clipEdge: true,
            duration:500,
            xAxis: {
                axisLabel: 'Date/Hour',
                showMaxMin: false,
                tickFormat: function(d){
                    if($scope.hourly === 'Y')
                        return d3.format(',f')(d);
                    else {
                        var dt = new Date(d);
                        dt.setTime(dt.getTime() + dt.getTimezoneOffset() * 60 * 1000);
                        return d3.time.format('%Y-%m-%d')(dt);
                    }
                }
            },
            yAxis: {
                axisLabel: 'Count',
                axisLabelDistance: -20,
                tickFormat: function(d){
                    return d3.format(',f')(d);
                }
            }
        }
    };

    $scope.data = [   {
  "key":"5-ISSUED",
  "values":[
     {
        "x":"2016-05-12",
        "y":"736"
     },
     {
        "x":"2016-05-11",
        "y":"1051"
     },
     {
        "x":"2016-05-10",
        "y":"1369"
     },
     {
        "x":"2016-05-09",
        "y":"937"
     },
     {
        "x":"2016-05-08",
        "y":"118"
     },
     {
        "x":"2016-05-07",
        "y":"59"
     },
     {
        "x":"2016-05-06",
        "y":"430"
     }
  ]
},
{
  "key":"4-PAID",
  "values":[{
        "x":"2016-05-12",
        "y":"628"
     },
     {
        "x":"2016-05-11",
        "y":"1052"
     },
     {
        "x":"2016-05-10",
        "y":"1624"
     },
     {
        "x":"2016-05-09",
        "y":"1256"
     },
     {
        "x":"2016-05-08",
        "y":"116"
     },
     {
        "x":"2016-05-07",
        "y":"59"
     },
     {
        "x":"2016-05-06",
        "y":"395"
     }
  ]
},
{
  "key":"0-ABANDONDED",
  "values":[
     {
        "x":"2016-05-12",
        "y":"89"
     },
     {
        "x":"2016-05-11",
        "y":"102"
     },
     {
        "x":"2016-05-10",
        "y":"77"
     },
     {
        "x":"2016-05-09",
        "y":"59"
     },
     {
        "x":"2016-05-08",
        "y":"2"
     },
     {
        "x":"2016-05-07",
        "y":"4"
     },
     {
        "x":"2016-05-06",
        "y":"49"
     }
   ]
 }
]

Link to Plunker

【问题讨论】:

    标签: angularjs d3.js nvd3.js angular-nvd3


    【解决方案1】:

    你在 y 中传递一个字符串值

     "x":"2016-05-09",
     "y":"59" //this is wrong should be a number not a string
    

    应该是如下数字:

     "x":"2016-05-09",
     "y":59 //this is the right way to give number
    

    更正代码here

    【讨论】:

    • 感谢 Cyril 感谢您抽出宝贵时间进行纠正。
    • @Apu 如果您觉得我已经回答了您的问题,您可以将其标记为答案,这是它的工作原理meta.stackexchange.com/questions/5234/…
    • 你好西里尔,我没有足够的声誉将其标记为答案,但它是完全正确的。
    猜你喜欢
    • 1970-01-01
    • 2017-03-06
    • 1970-01-01
    • 1970-01-01
    • 2021-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多