I am learning the wonderful libraries, dc.js and crossfilter.js and am making an example using a geochoropleth map.
I want to feed in some data and have the map draw the specific countries but the countries are not showing up. This is part of a much larger example and I'm trying to submit only the part I am having a problem with. I posted a jfiddle at https://jsfiddle.net/wheatgrass/93w6p6dc/6/
(but had a problem with it getting the cdns to work) where you (hopefully) can see the data and my crossfilter outputs. Everything is going to the console.log output.
Initially I had the data in a nested array, but read about cf needing "flattened" data, so I add two subset examples of flattened data, countries1 and countries2. I want to use countries2.
I tried using the reductio helper libs and (yay!) got the n1dimgroup to output by key "nid" and an array of countries with values. I did this by using the example in the Readme.md on the reductio github page. I could not find any examples in SO or elsewhere for what I am trying.
I need help with this part. How do I rewrite the reducer such that the n1dimgroup output is an object with key,values, like this?
{ key: Benin, value: 1}
{ key: Nepal, value: 2}
...
etc?
Your help and assistance would be greatly appreciated. Thank you. I have shortened the code below but data are on the jfiddle.
code below
<script>
//please see var countries2 on the jfiddle
var countries = [
"key":"Albania",
"value":2,
"key":"Jamaica",
"value":1,
"key":"Senegal",
"value":3,
"key":"Morocco",
"value":2,
"nid":"0",
},
{
"key":"Fiji",
"value":1,
"key":"Mongolia",
"value":1,
"key":"Uganda",
"value":1,
"nid":"36",
}
var n1 = crossfilter(countries2);
var n1dim = n1.dimension(function(d) { return d.nid});
var n1dimgroup = n1dim.group();
console.log("n1dim",n1dim.top(Infinity));
console.log("n1dimgroup",n1dimgroup.top(Infinity));
var reducer = reductio()
.exception(function(d) { return d.key; })
.exceptionCount(true)
.exceptionSum(function(d) { return d.value; });
reducer(n1dimgroup);
console.log('reducer', reducer);
console.log('n1dimgrouptop after reductio', n1dimgroup.top(Infinity));
console.log('n1dimgrouptop.key', n1dimgroup.top(Infinity).key);
console.log('n1dimgrouptop.value', n1dimgroup.top(Infinity).value);
</script>
How do I get the reducer to provide the output in key,value form in an object?