0

I'm trying to render different charts from an array named $scope.dataset with ng-repeat but it is not happening.

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

But I get this in firefox console-

Error: a.map is not a function

So I tried to put the same code in their plunkr - linechart-nvd3, and that did not work either. However the graph renders when I use the whole array i.e. $scope.dataset rather than using ng-repeat. Any help would be appreciated. Thank you.

4

1 回答 1

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 那么它将完美运行。

于 2016-07-02T15:08:10.543 回答