Skip to content

Instantly share code, notes, and snippets.

@edgardmota
Created April 8, 2020 17:47
Show Gist options
  • Save edgardmota/3f6f8a9ed90597866f507e901ef95f5a to your computer and use it in GitHub Desktop.
Save edgardmota/3f6f8a9ed90597866f507e901ef95f5a to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML>
<html>
<head>
<script>
window.onload = function () {
var confirmed = [];
var projection = [];
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
theme: "light2",
title:{
text: "Casos Oficiais de COVID-19"
},
axisX:{
valueFormatString: "D MMM",
crosshair: {
enabled: true,
snapToDataPoint: true
}
},
axisY: {
title: "Número",
crosshair: {
enabled: true
}
},
toolTip:{
shared:true
},
legend:{
cursor:"pointer",
verticalAlign: "bottom",
horizontalAlign: "left",
dockInsidePlotArea: true,
itemclick: toogleDataSeries
},
data: [{
type: "line",
showInLegend: true,
name: "Confirmados",
markerType: "square",
xValueFormatString: "DD/MM/YYYY",
color: "#F08080",
dataPoints: confirmed
},
{
type: "line",
showInLegend: true,
name: "Projeção",
color: "#CCCCCC",
lineDashType: "dash",
dataPoints: projection
}]
});
$.getJSON("https://covid-projection.herokuapp.com/BR/cases", function(data) {
$.each(data.cases, function(key, value){
confirmed.push({x: new Date(value[0]), y: parseInt(value[1])});
});
chart.render();
});
$.getJSON("https://covid-projection.herokuapp.com/BR/cases", function(data) {
$.each(data.pred, function(key, value){
projection.push({x: new Date(value[0]), y: parseInt(value[1])});
});
chart.render();
});
chart.render();
function toogleDataSeries(e){
if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
e.dataSeries.visible = false;
} else{
e.dataSeries.visible = true;
}
chart.render();
}
}
</script>
</head>
<body>
<div id="chartContainer" style="height: 300px; width: 100%;"></div>
<script type="text/javascript" src="https://canvasjs.com/assets/script/jquery-1.11.1.min.js"></script>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment