我用dc.js创建了一个仪表板。在我的仪表板中,有一个复选框,允许用户在计数和金额之间切换仪表板行为。为此,我为所有群组重新创建了crossfilter
reduceSum
个crossfilter
。 (虽然,我不知道这是否是正确的方法。)重新创建filtered
后,我还必须重新创建dc.js图表。
我认为这可能导致一些内存泄漏和性能问题,因为我为所有图表定义了Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/Users/admin/.rbenv/versions/2.2.3/bin/ruby -r ./siteconf20151101-96612-c518oi.rb extconf.rb
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
./../fbuffer/fbuffer.h:158:47: error: too few arguments provided to function-like macro invocation
VALUE result = rb_str_new(FBUFFER_PAIR(fb));
^
/Users/admin/.rbenv/versions/2.2.3/include/ruby-2.2.0/ruby/intern.h:793:9: note: macro 'rb_str_new' defined here
#define rb_str_new(str, len) __extension__ ( \
^
In file included from generator.c:1:
./../fbuffer/fbuffer.h:158:11: warning: incompatible pointer to integer conversion initializing 'VALUE' (aka 'unsigned long') with an expression of type 'VALUE (const char *, long)' [-Wint-conversion]
VALUE result = rb_str_new(FBUFFER_PAIR(fb));
^ ~~~~~~~~~~
generator.c:867:22: warning: '&&' within '||' [-Wlogical-op-parentheses]
return *p == '[' && *q == ']' || *p == '{' && *q == '}';
~~~~~~~~~~^~~~~~~~~~~~ ~~
generator.c:867:22: note: place parentheses around the '&&' expression to silence this warning
return *p == '[' && *q == ']' || *p == '{' && *q == '}';
^
( )
generator.c:867:48: warning: '&&' within '||' [-Wlogical-op-parentheses]
return *p == '[' && *q == ']' || *p == '{' && *q == '}';
~~ ~~~~~~~~~~^~~~~~~~~~~~
generator.c:867:48: note: place parentheses around the '&&' expression to silence this warning
return *p == '[' && *q == ']' || *p == '{' && *q == '}';
^
( )
3 warnings and 1 error generated.
make: *** [generator.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/admin/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/json-1.7.3 for inspection.
Results logged to /Users/admin/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-15/2.2.0-static/json-1.7.3/gem_make.out
An error occurred while installing json (1.7.3), and Bundler cannot continue.
Make sure that `gem install json -v '1.7.3'` succeeds before bundling.
事件,并且不知道如何关闭该事件。此外,在选中并取消选中复选框页面后,速度会变慢。
我的问题:是否还有另一种方法可以在不重新创建dc.js图表的情况下完全更改交叉过滤器数据?如果没有,如何正确删除dc.js图表以避免内存泄漏和性能问题?
答案 0 :(得分:1)
我会回答第一个问题但不回答第二个问题。 (记忆泄漏是一个重要的主题,但我不知道答案;如果你怀疑.on('filtered',...)
你可能会尝试.on('filtered', null)
,但我怀疑这是唯一的循环。)< / p>
回到如何替换数据。这应该很简单:只需将组和维度重新分配给图表,然后调用chart.render()
。 render
总是从头开始,所以它应该始终是安全的。更换组和维度后,即使redraw
通常也有效,因为dc.js图表只是从group.all()
提取数据并在维度上设置过滤器,所以如果你不关心它们替换那些。
减速的常见原因是创造了越来越多的群体和群体。同一个crossfilter实例上的维度,但听起来你是从头开始创建交叉过滤器,所以这不是问题。