Created
July 15, 2014 20:13
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------- | |
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