multiple datasets

409 views
Skip to first unread message

Laurence K

unread,
Jan 20, 2015, 8:51:00 AM1/20/15
to dc-js-us...@googlegroups.com
I have a simple dc.js dashboard based on a csv with headings of month, site, cost & product type.
It has 3 linked charts;

- bar chart cost by site
- line chart of cost by month
- pie chart of product type

all works fine, simple sum of costs as the groups - looks great

I have another csv with headings month, site, widgets produced

I want to create a new dashboard showing average cost per widget, using cost data from the first csv & widget data from the second.

How can I enable this new dashboard to filter by product type, when that column is in the costs csv but not the widgets csv?

Adam Reynolds

unread,
Jan 20, 2015, 8:56:58 AM1/20/15
to dc-js-us...@googlegroups.com
Merge the data. Download both, process them into a new array. Use that array of data to create your crossfilters from.

Note you'll need flags to notify you when both are downloaded to then know when to create the new merged dataset or just chain the functions.


--
You received this message because you are subscribed to the Google Groups "dc-js user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dc-js-user-gro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dc-js-user-group/d4624d02-1b30-4e0d-9025-c8e379185645%40googlegroups.com.

Laurence K

unread,
Jan 20, 2015, 9:50:28 AM1/20/15
to dc-js-us...@googlegroups.com
Hi Adam,

thanks for the quick response.

I have found some examples of doing this via queue.js or using underscore.js, the bit I can't quite get my head around is how to crossfilter it.

The datasets have 2 dimensions in common (month & site), the product dimension only applies to costs not widgets.

So I want to be able to see e.g. average cost per widget by site for a particular product type, that's where I am stuck.

Apologies if I am just being a bit thick here, I can't seem to find an example that does this.

Matt Traynham

unread,
Jan 20, 2015, 4:12:17 PM1/20/15
to dc-js-us...@googlegroups.com
I created a utility library that will let you merge Arrays of Objects pretty quickly.  

It's basically a join algorithm library built on top of LoDash.  All of the functions have the same syntax:

_.join(leftArray, leftArrayKeyAccessor, rightArray, rightArrayKeyAccessor)

Just pre-process the data before handing it off to Crossfilter.

Laurence Kelly

unread,
Jan 21, 2015, 4:12:16 AM1/21/15
to dc-js-us...@googlegroups.com

Thanks matt I'll have a look.

I think my issue is more about how to crossfilter when the data is in 2 levels of granularity like this e.g average cost per widget for a product group when the widgets total is only at site level.

--
You received this message because you are subscribed to a topic in the Google Groups "dc-js user group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dc-js-user-group/FamwYmSgTWg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dc-js-user-gro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dc-js-user-group/2181012f-d718-4f98-8ddf-d133c182e214%40googlegroups.com.

Matt Traynham

unread,
Jan 21, 2015, 1:36:01 PM1/21/15
to dc-js-us...@googlegroups.com
Joining aggregate data sets is quite a tricky problem.  

In theory, you could have multiple crossfilter instances for each data set.  One thing you'll have to figure out is when you filter one crossfitler instance, to make sure it filters the other.  As long as the two share a common dimension field, you could literally just copy the filters from one to the other.

Laurence K

unread,
Jan 22, 2015, 3:23:11 AM1/22/15
to dc-js-us...@googlegroups.com
Hi Matt, after varying my searching a bit I found a post on stackoverflow that suggests a couple of approaches to the same type of issue.

Ethan's suggestion of using just one crossfilter and managing the data aggregation at different key levels in the custom group functions appeals, because I need to calculate the average using cost from one 'dataset' and widgets from the other in a custom group function anyway.

Gordon's suggestion of using a custom dimension wrapper also sounds good, but I can see exactly how to do it Ethan's way whereas a dimension wrapper would be a whole voyage of discovery.
Reply all
Reply to author
Forward
0 new messages