xxxxxxxxxx
1
<input type="date" id="dateSelect">
2
<canvas id="chart-async-data-example"></canvas>
1
1
xxxxxxxxxx
1
const chart = document.getElementById('chart-async-data-example');
2
const chartInstance = new mdb.Chart(chart, { type: 'bar' });
3
$(document).ready(function() {
4
$("#dateSelect").change(function() {
5
var dateSelect = $("#dateSelect").val();
6
$.ajax({
7
url: `https://api.covid19api.com/total/country/poland/status/confirmed?from=2020-10-01T00:00:00Z&to=2020-12-01T00:00:00Z`,
8
type: 'get',
9
data: {
10
dateSelect: dateSelect
11
},
12
dataType: 'json',
13
success: function(result) {
14
const dataset = result.map((obj) => obj['Cases']);
15
const labels = result.map((obj) => obj['Date'].substr(0, 10));
16
console.log(result);
17
console.log(chartInstance);
18
chartInstance.update({
19
labels,
20
datasets: [
21
{
22
color: '#FFCDD2',
23
data: dataset,
24
label: 'Number of cases',
25
pointRadius: 0,
26
borderColor: dataset.color,
27
},
28
],
29
});
30
}
31
});
32
});
33
});
34
Console errors: 0