Skip to content

Instantly share code, notes, and snippets.

@wetzler
Created February 13, 2014 23:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wetzler/8986385 to your computer and use it in GitHub Desktop.
Save wetzler/8986385 to your computer and use it in GitHub Desktop.
Pseudocode for making a cumulative line chart with Keen IO series data. Use this to make a running total of users, for example. The gist assumes that the timeframe being queried includes all of the data.
Keen.onChartsReady(function() {
var series = new Keen.Series("registrations", {
analysisType: "count",
timeframe: "last_30_weeks",
interval: "weekly"
});
series.getResponse(function(response){
keenData = response.result;
cumulativeData = [] // create a new object to store the cumulative data results
runningTotal = 0
for each result in keenData {
registrations = keenData["result"]
runningTotal = runningTotal + registrations
newDataPoint = {
"value": runningTotal,
"timeframe": keenData["timeframe"]
}
cumulativeData << newDataPoint
i++
}
//Create a LineChart visualization
var myLineChart = new Keen.LineChart("placeholder", {
height: "300",
width: "600",
title: "cumulative registrations"
});
//Draw the visualization into a div
myLineChart.draw(document.getElementById("myDiv"), cumulativeData);
})
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment