Last active
January 3, 2016 07:19
-
-
Save rebeccastandig/8428804 to your computer and use it in GitHub Desktop.
How to create a Keen Line Chart with cumulative data.
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
| 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