NVD3访问图表对象

时间:2015-10-07 17:44:26

标签: javascript d3.js nvd3.js

In previous version's of nvd3您可以执行以下操作来访问图表/图表对象。

chart = nv.graphs[0];

然而,在最近的版本中,这似乎已被删除:

nv.graphs -> undefined
nv.graphs[0] -> TypeError: nv.graphs is undefined

是否有其他方法可以访问图表元素?

chart = nv.graphs[0];
a = chart.brushExtent();

这里有一个简单的jsfiddle,你可以在其中看到这个,

http://jsfiddle.net/0m8jzetx/3/

Here is the git issue where they remove it.

1 个答案:

答案 0 :(得分:1)

I don't have a real answer, but have found something that may help accessing brushextents:
Rather than declaring chart as a global var, you can declare 2 global var for your extents, and update them when brush is updated, like so:

chart.dispatch.on('brush.update', function(b) {
  curve_focus_min = b.extent[0];
  curve_focus_max = b.extent[1];
});