dc.js rolling sum per year and store

16 views
Skip to first unread message

Thanasis Staveris

unread,
Aug 8, 2017, 11:29:47 AM8/8/17
to dc-js user group

 am new to dc.js and if any one can help would be really appreciated. I have the following data:

Store   year    earnings
A   2011    1000
A   2012    2000
A   2013    2000
A   2014    3000
B   2012    200
B   2012    300
B   2012    500
B   2014    3000
B   2015    4000
C   2013    2000
C   2013    200
C   2015    1200
C   2016    4000

What i would like to do is to use dc.js to get cumulative sum per store per year and display it in a series chart. the cumulative sum per store per year would be

Store   year    earnings
    A   2011    1000
    A   2012    3000
    A   2013    5000
    A   2014    8000
    B   2012    1000
    B   2014    4000
    B   2015    8000
    C   2013    2200
    C   2015    3400
    C   2016    7400

I have searched around and saw that this can be done for one dimention using functions like

function createCumulativeGroup(source_group) {
        return {
            all:function () {
                var cumulate = 0;
                return source_group.all().map(function(d) {
                    cumulate += d.value;

                    return {key:d.key, value:cumulate};
                });
            }
        };
    }

But the above doesn't work , can you give me a hint?

check also the jsfiddle: https://jsfiddle.net/thyfoubq/10/

Gordon Woodhull

unread,
Aug 8, 2017, 5:43:37 PM8/8/17
to dc-js-us...@googlegroups.com

I've also edited the question to make it clear this is a question about extending cumulative sums to work with the series chart.

Time is tight for me right now but I hope to have a look later in the week.
--
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/c688d8a9-bcc8-4c5d-b4ca-67ccca843d9e%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages