我一直在努力奋斗3天,没有运气。
一旦我应用了一些过滤器,我想得到reduceCount值,我猜这是基本的 但每个教程或博客,谈论crossfilter的文档都显示了同样的例子:(
例如:我如何获得仅用于签证的不同国家/地区的数量?
var payments = crossfilter([
{date: "2011-11-14T16:17:54Z", country: 'DE', total: 190, tip: 100, type: "tab"},
{date: "2011-11-14T16:20:19Z", country: 'MX', total: 190, tip: 100, type: "tab"},
{date: "2011-11-14T16:28:54Z", country: 'US', total: 300, tip: 200, type: "visa"},
{date: "2011-11-14T16:28:54Z", country: 'US', total: 200, tip: 200, type: "visa"},
{date: "2011-11-14T16:30:43Z", country: 'FR', total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T16:48:46Z", country: 'CA', total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T16:53:41Z", country: 'MX', total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T16:54:06Z", country: 'ES', total: 100, tip: 0, type: "cash"},
{date: "2011-11-14T16:58:03Z", country: 'US', total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T17:07:21Z", country: 'CA', total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T17:22:59Z", country: 'US', total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T17:25:45Z", country: 'ES', total: 200, tip: 0, type: "cash"},
{date: "2011-11-14T17:29:52Z", country: 'FR', total: 200, tip: 100, type: "visa"}
]);
var typeDimension = payments.dimension(function(d) { return d.type; });
var totalDimension = payments.dimension(function(d) { return d.total; });
var countryDimension = payments.dimension(function(d) { return d.country; });
var totalGroup = totalDimension.group();
var typeGroup = typeDimension.group();
var countryGroup = countryDimension.group();
var totalSize = totalGroup.reduceCount().size(); // 5 Distinct total amounts
var typeSize = typeGroup.reduceCount().size(); // 3 Distinct types
var countrySize = countryGroup.reduceCount().size(); // 6 Distinct countryes
var visaFilter = typeDimension.filter('visa'); // Filter by Visa type
payments.groupAll().reduceCount().value(); // Ok We have 3 payments
countryDimension.top(Infinity); // This will return the 3 payment objects
countryDimension.group().reduceCount().size(); // Still shows 5 Distinct amounts
countryDimension.group(function(d, v){console.log(d, v); return d;});
countryDimension.group().all(); // Will return group by countryes and number of payment on each country
非常感谢!