Sunday, 15 June 2014

javascript - How to select elements from array field in dc.js / crossfilter / d3 and use each of them as separate data point for chart? -



javascript - How to select elements from array field in dc.js / crossfilter / d3 and use each of them as separate data point for chart? -

for example, json element, "categories" field array:

{"city": "san francisco, ca", "business_id": "15", "name": "parastructure", "date": "2014", "founder_education": "stanford", "categories": ["big data", "big info analytics", "data visualization", "enterprise software"], "amount": "500000000"}

using dc.js, how go selecting each element in array , adding chart visualization?

var categories = ndx.dimension(function (d) { homecoming d.categories; // wouldn't work

});

var categoriesgroup = categories.group();

crossfilter works best flat arrays of records. if don't thought of cut down function creating maps, suggested in comments above, can create flat array out of info "multiplying out" categories records.

so, (using underscores's clone function duplicate records):

var product = []; for(var r in records) { for(var = 0; < r.categories.length; ++i) { var r2 = _.clone(r); delete r2.categories; r2.category = r.categories[i]; product.push(r2); } }

(warning: not tested.) now, used have n categories in record, you'll have n records, 1 each category. , can cut down on category okay now.

... of course of study might create other calculations messy or not work (some hints here), why suggested other answer first. unfortunately crossfilter not designed dealing multi-valued fields.

javascript json d3.js dc.js crossfilter

No comments:

Post a Comment