为什么一个图表不能在dc.js中过滤另一个图表? [英] why does one chart not filter another in dc.js?

查看:147
本文介绍了为什么一个图表不能在dc.js中过滤另一个图表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解直流组图表的方式。所以一个过滤器的变化反映在所有其他。
我有一个简单的代码与两个系列图表。当我画一个刷子,它不过滤另一个。不知道为什么?有人可以请快速看看小代码和建议。

I am not able to understand how dc groups chart. So that the change in one filter reflects in all others. I have a simple code with two series charts. When I draw brush on one, it does not filter the other. Not sure why ? Can someone please have a quick look at the small code and suggest.

d3.csv("data/compareData.txt", function(data) {

  ndx = crossfilter(data);
  runDimension = ndx.dimension(function(d) {return [+d3.time.format.iso.parse(d.timestamp), +d.meterid]; });
  frequencyGroup = runDimension.group().reduceSum(function(d) { return +d.frequency; });
  magnitudeGroup = runDimension.group().reduceSum(function(d) { return +d.magnitude; });


 frequencyChart
    .width(768)
    .height(480)
    .chart(function(c) { return dc.lineChart(c).interpolate('basis'); })
    .x(d3.time.scale().domain([1366621166000, 1366621179983]))
    .y(d3.scale.linear().domain([90, 100]))
    .brushOn(true)
    .yAxisLabel("Measured Speed km/s")
    .xAxisLabel("Run")
    .elasticY(true)
    .dimension(runDimension)
    .group(frequencyGroup)
    .mouseZoomable(false)
    .seriesAccessor(function(d) {return +d.key[1];})
    .keyAccessor(function(d) {return +d.key[0];})
    .valueAccessor(function(d) {return +d.value;})
    .legend(dc.legend().x(350).y(350).itemHeight(13).gap(5).horizontal(1).legendWidth(140).itemWidth(70));
  frequencyChart.yAxis().tickFormat(function(d) {return d3.format(',d')(d);});
  frequencyChart.margins().left += 40;

 magnitudeChart
    .width(768)
    .height(480)
    .chart(function(c) { return dc.lineChart(c).interpolate('basis'); })
    .x(d3.time.scale().domain([1366621166000, 1366621179983]))
    .y(d3.scale.linear().domain([90, 100]))
    .brushOn(true)
    .yAxisLabel("Measured Speed km/s")
    .xAxisLabel("Run")
    .elasticY(true)
    .dimension(runDimension)
    .group(magnitudeGroup)
    .mouseZoomable(false)
    .seriesAccessor(function(d) {return  +d.key[1];})
    .keyAccessor(function(d) {return +d.key[0];})
    .valueAccessor(function(d) {return +d.value;})
    .legend(dc.legend().x(350).y(350).itemHeight(13).gap(5).horizontal(1).legendWidth(140).itemWidth(70));
  magnitudeChart.yAxis().tickFormat(function(d) {return d3.format(',d')(d);});
  magnitudeChart.margins().left += 40;

      dc.renderAll();

});


推荐答案

您使用相同的维度


一个分组与交叉过滤器的当前过滤器相交,除了
相关维度的过滤器。因此,组方法只考虑满足每个过滤器(除了此维度的过滤器)的
记录。所以,
如果交叉过滤器的付款被类型和总额过滤,然后
组合总只观察过滤器的类型。

a grouping intersects the crossfilter's current filters, except for the associated dimension's filter. Thus, group methods consider only records that satisfy every filter except this dimension's filter. So, if the crossfilter of payments is filtered by type and total, then group by total only observes the filter by type.

crossfilter API文档

一个解决方案是创建一个类似于 runDimension runDimension2 使用此维度。

One solution is to create a runDimension2 similar to runDimension and do your second chart using this dimension instead.

这篇关于为什么一个图表不能在dc.js中过滤另一个图表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆