0

I'm using Angular-nvD3. I have a simple chart that looks like this:

HTML:

<nvd3 options="options" data="data"></nvd3>

JS:

$scope.options = {
        chart: {
            type: 'pieChart',
            height: 450,
            x: function (d) { return d.key; },
            y: function (d) { return d.y; },
            showLabels: true,
            duration: 1100,
            showLegend: false
        }
    };

My data object is just a simple array of objects with key and y properties. On some DOM event, I update the data from the server and change the data object. When I do this, my chart is resized.

Why is this happening and how can I prevent it?

enter image description here

Update:

// This is the function that is called on the DOM event.
var loadAllData = function () {
    var result = getData();

    result.$promise.then(function (returnedAmounts) {
        loadChartsData(returnedAmounts.expenses, $scope.data);
    }, function (error) {
        // Error.
    });
}

var loadChartsData = function (group, chartsData) {
    // Iterate over the group
    for (var i = 0; i < group.length; i++) {
        chartsData[i] = {
            key: group[i].name || group[i].key,
            y: group[i].amount
        };
    }
}
4

1 に答える 1

0

config.deepWatchData = false を設定してみてください。そのようにすると、チャートは指示された場合にのみ更新されます。(api.refresh を使用)

deepWatchData

于 2016-01-25T07:38:30.383 に答える