【问题标题】:Angular nvd3 sunburst does not update with $scope.data changeAngular nvd3 sunburst 不会随着 $scope.data 的变化而更新
【发布时间】:2016-07-21 08:52:07
【问题描述】:

用例: 当 api 中的数据发生变化时,$scope.data 也会发生变化。我可以看到 html 中的数据变化。预计会更新旭日图。

核心代码如下:

控制器:

var grabData=function(){
  $http.get('someApi').then(function success(response){
  $scope.options = {
        chart: {
            type: 'sunburstChart',
            width:450,
            height: 450,
            color: d3.scale.category20c(),
            duration: 250,
            mode: 'size',
            useInteractiveGuideline:true,
        }
    };
    $scope.config = {
        visible: true, // default: true
        disabled: false, // default: false
        refreshDataOnly: true, // default: true
        deepWatchOptions: true, // default: true
        deepWatchData: true, // default: true
        deepWatchDataDepth: 2, // default: 2
        debounce: 10 // default: 10
    };
        $scope.data = [];
        $scope.data.push({"name":"PORTFOLIO", "children":response.data});
    },function error(response){
      $scope.all = response.statusText;
  });};

HTML:

<div class="col-md-6 col-md-offset-1">
  <nvd3 options="options" data="data" config="config" class="with-3d-shadow with-transitions"></nvd3>
</div>

问题: 现在,当 api 中的数据发生变化时,$scope.data 也会发生变化。我可以看到 html 中的数据变化。但是旭日形图在我手动刷新页面之前根本不会更新

【问题讨论】:

  • 你能为此准备一个plunker吗?你可以使用已经安装好的 Angular/NVD3 fork 我的:plnkr.co/N6lWYU
  • 所以我有一个服务可以在后端数据发生变化时发送信号。一旦控制器收到信号,就会调用函数grabData() 并更新$scope.data。 HTML 反映了数据,这意味着 $scope.data 已更改但图表未更新。代码如上! @Atais
  • deepWatchData: true 应该可以解决问题并更新图表。它没有,这就是为什么你应该尝试用 plunker 复制这个问题。使用这种方法,您将隔离问题。问题可能出在您应用程序的其他地方。
  • 图表根本不应该呈现,以防数据错误,不是吗?我会尽快更新 plunker。
  • 可能不应该,但好吧......它是javascript。

标签: javascript angularjs angularjs-scope angular-nvd3


【解决方案1】:

所以修复很简单,你必须通过 refreshDataOnly: false。

config="{refreshDataOnly: false}" 在您的配置中-

<nvd3 options="options" data="sunburst" config="{refreshDataOnly: false}" class="with-3d-shadow with-transitions"></nvd3>

【讨论】:

    猜你喜欢
    • 2016-10-27
    • 1970-01-01
    • 2017-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    相关资源
    最近更新 更多