Skip to content

Instantly share code, notes, and snippets.

@wetzler
Created July 15, 2014 20:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wetzler/4f70beaed4010173810f to your computer and use it in GitHub Desktop.
Save wetzler/4f70beaed4010173810f to your computer and use it in GitHub Desktop.
Recipe for Keen IO line chart with cumulative data (V2 Of Keen JS library)
-------------------------------
Line Chart with Cumulative Data
-------------------------------
This is an example for how you can create a line chart with data that is shown cumulatively.
.. note::
This example is current for our JS SDK v2.1.2 only. It does not apply to v3+
.. code-block:: javascript
Keen.onChartsReady(function(){
var loginsPreviousWeek = new Keen.Series("logins", {
analysisType: "count",
timeframe: "previous_7_days",
interval: "daily"
});
//Get the result of the query and add the results cumulatively.
loginsPreviousWeek.getResponse(function(response){
var result = response.result;
var whichResult = 0;
var cumulativeResult = 0;
while (whichResult < result.length){
cumulativeResult = cumulativeResult + result[whichResult].value
result[whichResult].value = cumulativeResult
whichResult++
};
//Create a LineChart visualization for that Series.
var myLineChart = new Keen.LineChart(loginsPreviousWeek, {
height: "300",
width: "600",
label: "logins",
title: "logins previous 7 days"
});
//Draw the visualization into a div
myLineChart.draw(document.getElementById("myDiv"), response);
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment