Last active
October 9, 2017 13:51
-
-
Save drio/877ee00e7543e29d527e6747c99bf8c9 to your computer and use it in GitHub Desktop.
Using the js SDK to load a simple chart
This file contains 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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> </style> | |
<div id="container0" style="height: 250px; width: 600px"></div> | |
<script src="https://sdk.librato.com/regular/librato-sdk-v1.2.3-min.js"></script> | |
<script> | |
var refresh_interval = 30000, | |
default_duration = 3600, | |
endTime = Math.round(+new Date()/1000), | |
startTime = endTime - default_duration, | |
chart = null, | |
opts = {}, | |
chart_id = '4052591'; | |
opts = { | |
id : chart_id, | |
apiToken : 'TOKEN', | |
email : 'EMAIL', | |
renderTo : document.getElementById('container0'), | |
timezoneOffset: 60 * 4, // Local time | |
startTime : startTime, | |
endTime : endTime, | |
dynamicSource : '*' | |
} | |
function iFn() { | |
var nowDate = new Date(); | |
chart.setDateInterval({ | |
startDate: new Date(nowDate - (default_duration*1000)), | |
endDate : nowDate | |
}); | |
} | |
function setUpdateTimeout() { | |
window.setInterval(iFn, refresh_interval); | |
} | |
chart = new LibratoMetrics.Chart(opts); | |
chart.refreshFromApi().then(setUpdateTimeout); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment