Crossfilter: Order crossfilter dimension based on another dimension

I asked a question here about calculating percent change using crossfilter with dc.js but stumbled across another more basic question.

If I wanted to get (and use) the first my_quantity value grouped for each country ordered by received_day to use in a calculation, how can I do that?

eg Assuming the below data contains the earliest and lastest samples:

country_id,received_day,product_type,my_quantity
US, 2017-04-16, Media, 100
US, 2017-04-17, Media, 120
US, 2017-04-19, Media, 40
US, 2017-04-22, Media, 60
GB, 2017-04-16, Media, 30
GB, 2017-04-21, Media, 30
GB, 2017-04-23, Media, 60
JP, 2017-04-16, Media, 10
JP, 2017-04-22, Media, 10
US, 2017-04-16, Furniture, 100
US, 2017-04-17, Furniture, 120
US, 2017-04-19, Furniture, 40
US, 2017-04-22, Furniture, 60
...
US, 2017-08-01, Media, 400
GB, 2017-08-01, Media, 300
JP, 2017-08-01, Media, 200

then I'd want like to be able to get the earliest (and latest date as well so I could get percent change, but starting with this)...

US, 2017-04-16, 200 (media + furniture)
GB, 2017-04-17, 30
JP, 2017-04-22, 10

If I start with a country_dim and group it

var country_dim = ndx.dimension(function (d) { return d['country_id']; })
var country_group = country_dim.group();

I will lose all the dates.

I could group by received_day and country and go through the results for the first and last day for each country? But then I would probably have to do regex on the combined string to get that back?

As mentioned, I'm using dc.js and would like to display a percent change when a time period is changed based on the brush. Any help or alternatives appreciated.

链接地址: http://www.djcxy.com/p/32762.html

上一篇: Hibernate复合关键标准加入

下一篇: Crossfilter:基于另一个维度来命令crossfilter维度