角nvd3问题,未能及时更新图表设置数据时newData [英] Angular-nvd3 issue, failed to update chart when set data to newData
问题描述
这是一个奇怪的问题不仅是关于 nvd3指令
,我已经steped到指令源$ C $ C,但找不到原因。结果
我把它放在 plunker ,开关注释行34和35中的 app.js 将显示的问题。结果
如果我设置$ scope.data一个新值,图表效果很好,但如果我设置了newData,图表将无法正常工作。结果
我已经调试角nvd3指令,当我改变在整个数据对象中,$表(数据)的(角nvd3.js线320)的仍工,但scope.chart.update()不工作正确的。我没有任何地方发现nvd3.js持有图表数据,所以我真的不知道发生了什么,为什么不工作....
It is a strange issue not only about nvd3 directive
, I have steped into the directive source code, but still not find the reason.
I put it in plunker, switch comment line 34 and 35 in app.js will show the issue.
if I set a new value in $scope.data, the chart works well, but if I set a newData, the chart will not work.
I've debug the angular-nvd3 directive, when I change the whole data object, the $watch('data') (angular-nvd3.js line 320) still work, but the scope.chart.update() not working correct. I didn't found anywhere that nvd3.js hold the chart data, so I really don't know what happend, why not working....
任何意见将是preciate!
Any comment will be a preciate!
推荐答案
我相信这是nvd3如何使用D3数据绑定的怪癖。
I believe this is a quirk of how nvd3 is using d3 data-binding.
初始数据数组势必像一个标准的D3可视化的DOM,并持有对它的引用。当你修改指令的阵列,它会触发一个重绘并且由于它是在同一阵列(参考吧),绑定的数据发生变化,情节正常重绘。
The initial data array is bound to the DOM like a standard d3 visualization and holds a reference to it. When you modify the array in the directive, it triggers a redraw and since it's the same array (reference to it), the bound data is changed and the plot redraws normally.
当你改变第一次抽签后阵,引擎盖下,阵列仍然数据绑定是初始阵列(一个无数据)。该指令还触发重新绘制,但没有数据。
When you change the array after the first draw, under the hood, the array that still data-binded is the initial array (the one with no data). The directive still triggers a re-draw but with no data.
要做到你想要什么,而不是调用 $范围$适用();
GET API
进入 $范围
与
To do what you want, instead of calling $scope.$apply();
get api
into the $scope
with:
<nvd3 options="options" data="data" api="api" config="{refreshDataOnly: true}"> </nvd3>
然后使用:
$scope.api.updateWithData($scope.data);
例如。
这篇关于角nvd3问题,未能及时更新图表设置数据时newData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!