Cumulative value of each interval in a series

Append a new series showing the cumulative value of an interval query

by keen

HTML

<script src="https://d26b395fwzu5fz.cloudfront.net/3.4.0/keen.min.js?date=2016-02-17"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.js"></script>
<div id="chart"></div>

JavaScript

var client = new Keen({
    projectId: "53eab6e12481962467000000",
    readKey: "d1b97982ce67ad4b411af30e53dd75be6cf610213c35f3bd3dd2ef62eaeac14632164890413e2cc2df2e489da88e87430af43628b0c9e0b2870d0a70580d5f5fe8d9ba2a6d56f9448a3b6f62a5e6cdd1be435c227253fbe3fab27beb0d14f91b710d9a6e657ecf47775281abc17ec455"
});

Keen.ready(function(){
    var query = new Keen.Query("count", {
        eventCollection: "user_action",
        timeframe: {
  			start: "2013-12-01",
  			end: "2015-02-01"
		},
        interval: "every_2_weeks"
    });
    var chart = new Keen.Dataviz()
        .library("c3")
        .el(document.getElementById("chart"))
        .height(300)
        .chartOptions({
            axis: {
                x: {
                    type: 'timeseries',
                    tick: {
                        count: 6,
                        format: '%Y-%m-%d'
                    }
                }
            }
        })
        .prepare();
    
    client.run(query, function(){
        var total = null;
        chart
            .parseRequest(this)
            .call(function(){
                this.dataset.appendColumn("Cumulative", function(row){
                    total += row[1];
                    return total;
                });
                // Delete original if necessary
                // this.dataset.deleteColumn(1);
            })
            .render();
    });
});