Skip to content

Instantly share code, notes, and snippets.

@EddyVerbruggen
Last active March 16, 2020 16:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save EddyVerbruggen/4b196f8ee3187e735487c556c59f43fb to your computer and use it in GitHub Desktop.
Save EddyVerbruggen/4b196f8ee3187e735487c556c59f43fb to your computer and use it in GitHub Desktop.
Grafana Corona widget
<!--
- 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>
@EddyVerbruggen
Copy link
Author

This is what the widget looks like (Global and NL versions):

Screenshot 2020-03-16 at 17 40 03

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment