Skip to content

Instantly share code, notes, and snippets.

@jderrett
Last active August 29, 2015 14:04
Show Gist options
  • Save jderrett/2f9ac3651edfe977380e to your computer and use it in GitHub Desktop.
Save jderrett/2f9ac3651edfe977380e to your computer and use it in GitHub Desktop.
librato_chart_example.html
<!DOCTYPE html>
<head>
<!-- They'll need there own version of jquery or whatever -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://sdk.librato.com/librato-sdk-v0.5.1-min.js"></script>
</head>
<body>
<div id="thegraph">
</div>
<input type="text" name="source" placeholder="dynamic source"></input>
<script type="text/javascript">
var hoursBack = 6;
var msPerHour = 1000 * 3600;
var startEpoch = Math.floor((new Date()).getTime() - hoursBack * msPerHour);
var startDate = new Date(startEpoch);
var opts = {
email: "me@example.com",
apiToken: "ABCD1234",
divID: "thegraph",
instrumentID: 30868334,
startDate: startDate,
source: 'austin'
}
var graph = new LibratoMetrics.LineGraph(opts);
var update = function(source) {
graph.model.setDynamicSource(source);
}
$('input[name="source"]').on('keyup', function(e) {
// Hitting the enter key
if (e.keyCode == 13) {
update($(this).val());
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment