Skip to content

Instantly share code, notes, and snippets.

@rebeccastandig
Last active January 3, 2016 07:28
Show Gist options
  • Select an option

  • Save rebeccastandig/8429171 to your computer and use it in GitHub Desktop.

Select an option

Save rebeccastandig/8429171 to your computer and use it in GitHub Desktop.
How to create a Keen Number that divides the results of two different queries.
Keen.onChartsReady(function(){
//Create a Metric containing our total number of logins.
var myMetric = new Keen.Metric("logins", {
analysisType: "count"
});
//Create a Metric containing our total number of registers.
var myMetric2 = new Keen.Metric("registers", {
analysisType: "count"
})
myMetric.getResponse(function(response){
firstValue = response.result;
myMetric2.getResponse(function(nextResponse){
secondValue = nextResponse.result;
divided = firstValue/secondValue;
console.log(divided);
//Create a Number visualization for that metric.
var myNumberVisualization = new Keen.Number(myMetric2, {
height: "300",
width: "600",
label: "total logins"
});
//Draw the visualization in a div
myNumberVisualization.draw(document.getElementById("myDiv"), {"result":divided});
})
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment