adding DrugsChartView

This commit is contained in:
Frank Knoll
2024-07-27 22:57:02 +02:00
parent 4a837ed175
commit 1374d4a73f
1042 changed files with 2186 additions and 12 deletions

View File

@@ -0,0 +1,71 @@
class DrugsChartView {
#canvas;
#chart;
constructor(canvas) {
this.#canvas = canvas;
}
displayChart(drugDescr) {
if (this.#chart != null) {
this.#chart.destroy();
}
this.#chart = new Chart(
this.#canvas,
{
type: 'bar',
plugins: [ChartDataLabels],
data: this.#getData(drugDescr),
options: this.#getOptions()
});
}
setData(histoDescr) {
const data = this.#getData(histoDescr);
this.#chart.config.data = data;
this.#chart.update();
}
#getData(drugDescr) {
return {
labels: drugDescr['DRUG'],
datasets: [{
label: 'FATAL',
data: drugDescr['FATAL'],
backgroundColor: '#FF0000'
},
{
label: 'RECOVERED',
data: drugDescr['RECOVERED'],
backgroundColor: '#00FF00'
}]
};
}
#getOptions() {
return {
plugins: {
datalabels: {
anchor: 'end',
align: 'top'
}
},
title: {
display: true,
position: 'top'
},
scales: {
y: {
ticks: {
precision: 0
},
title: {
display: true,
text: 'Frequency'
}
}
}
};
}
}