【问题标题】:Angular-nvD3(krispo) single line chart with ng-repeat带有 ng-repeat 的 Angular-nvD3(krispo) 单线图
【发布时间】:2016-07-02 14:42:25
【问题描述】:

我正在尝试使用 ng-repeat 从名为 $scope.dataset 的数组中呈现不同的图表,但它没有发生。

<div ng-repeat="data in dataset">
   <nvd3 options="options" data="data" class="with-3d-shadow with-transitions"></nvd3>
</div>

但我在 Firefox 控制台中得到了这个-

Error: a.map is not a function

所以我尝试在他们的 plunkr 中放入相同的代码 - linechart-nvd3,但这也不起作用。然而,当我使用整个数组即$scope.dataset 而不是使用ng-repeat 时,图形会呈现。任何帮助,将不胜感激。谢谢。

【问题讨论】:

    标签: javascript angularjs angularjs-ng-repeat linechart angular-nvd3


    【解决方案1】:

    在你的 sinAndCos() 方法中试试这个代码:

    //Line chart data should be sent as an array of series objects.
                return [
                    [{
                        values: sin,      //values - represents the array of {x,y} data points
                        key: 'Sine Wave', //key  - the name of the series.
                        color: '#ff7f0e',  //color - optional: choose your own line color.
                        strokeWidth: 2,
                        classed: 'dashed'
                    }],
                    [{
                        values: cos,
                        key: 'Cosine Wave',
                        color: '#2ca02c'
                    }],
                    [{
                        values: sin2,
                        key: 'Another sine wave',
                        color: '#7777ff',
                        area: true      //area - set to true if you want this line to turn into a filled area chart.
                    }]
                ];
    

    所以在你的 plunkr 中输入相同的代码 - http://plnkr.co/edit/lBKFld?p=preview

    注意:Angular-nvD3 图表您必须发送对象数组。在这里,我将每个元素作为对象数组发送。现在,如果您使用 ng-repeat,那么它将完美运行。

    【讨论】:

      猜你喜欢
      • 2013-03-12
      • 1970-01-01
      • 1970-01-01
      • 2017-04-16
      • 2014-10-30
      • 2023-03-05
      • 2013-08-26
      • 1970-01-01
      • 2014-10-26
      相关资源
      最近更新 更多