Last active
March 16, 2020 16:52
-
-
Save EddyVerbruggen/4b196f8ee3187e735487c556c59f43fb to your computer and use it in GitHub Desktop.
Grafana Corona widget
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
<!-- | |
- Add a 'Text' widget with the content below (set 'mode' to 'html'). | |
- Make sure to enable JS parsing for this widget by setting the 'disable_sanitize_html' property to 'true' in your grafana.ini. | |
- For more detailed info, check out fi. https://www.worldometers.info/coronavirus/ | |
- STAY SAFE FOLKS! | |
--> | |
<center> | |
<div style="font-size: 20px">🦠<span id="confirmed"/></div> | |
<div style="font-size: 16px">💀<span id="deaths" /><span id="deathrate" style="color: #555; padding-left: 8px"/></div> | |
</center> | |
<script type="text/javascript"> | |
var formatNr = input => { | |
// formats fi. 120000 to 120,000 (set the "," character below to "." to format as 120.000) | |
return input.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); | |
} | |
$(document).ready(() => { | |
// to get country-specific data, use fi. https://covid19.mathdro.id/api/countries/NL instead of the url below | |
$.ajax({url: "https://covid19.mathdro.id/api"}).done( | |
data => { | |
$("#confirmed").text(formatNr(data.confirmed.value)); | |
$("#deaths").text(formatNr(data.deaths.value)); | |
$("#deathrate").text((Math.round((data.deaths.value / data.confirmed.value) * 10000) / 100) + " %"); | |
} | |
); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is what the widget looks like (Global and NL versions):