labeling axes in scatter chart

This commit is contained in:
frankknoll
2023-11-09 10:22:20 +01:00
parent f1262e8ab6
commit 99b210e4ff
2 changed files with 48 additions and 42 deletions

View File

@@ -6,7 +6,7 @@ class PageInitializer {
PageInitializer.#configureSymptom(symptom); PageInitializer.#configureSymptom(symptom);
PageInitializer.#configureVaccine(vaccine); PageInitializer.#configureVaccine(vaccine);
PageInitializer.#symptomVsSymptomChartView = new SymptomVsSymptomChartView(symptomVsSymptomChartViewElement); PageInitializer.#symptomVsSymptomChartView = new SymptomVsSymptomChartView(symptomVsSymptomChartViewElement);
PageInitializer.#symptomVsSymptomChartView.displayChart('Immunosuppression', 'Immunoglobulin therapy'); PageInitializer.#symptomVsSymptomChartView.loadAndDisplayChart('Immunosuppression', 'Immunoglobulin therapy');
} }
static #configureSymptom({ symptomSelectElement, prrByVaccineTableElement, downloadPrrByVaccineTableButton }) { static #configureSymptom({ symptomSelectElement, prrByVaccineTableElement, downloadPrrByVaccineTableButton }) {

View File

@@ -8,21 +8,26 @@ class SymptomVsSymptomChartView {
} }
// FK-TODO: refactor // FK-TODO: refactor
displayChart(symptomX, symptomY) { loadAndDisplayChart(symptomX, symptomY) {
Promise
.all([symptomX, symptomY].map(symptom => PrrByVaccineProvider.getPrrByVaccine(symptom)))
.then(([prrByLotX, prrByLotY]) => this.#displayChart(prrByLotX, prrByLotY, symptomX, symptomY));
}
#displayChart(prrByLotX, prrByLotY, symptomX, symptomY) {
if (this.#chart != null) { if (this.#chart != null) {
this.#chart.destroy(); this.#chart.destroy();
} }
// FK-TODO: move PrrByVaccineProvider.getPrrByVaccine() calls out of this function
Promise
.all([symptomX, symptomY].map(symptom => PrrByVaccineProvider.getPrrByVaccine(symptom)))
.then(([prrByLotX, prrByLotY]) => {
const chartData = SymptomVsSymptomChartDataProvider.getChartData({ prrByLotX, prrByLotY }); const chartData = SymptomVsSymptomChartDataProvider.getChartData({ prrByLotX, prrByLotY });
const data = { const data = {
datasets: [{ datasets:
[
{
labels: chartData.labels, labels: chartData.labels,
data: chartData.data, data: chartData.data,
backgroundColor: 'rgb(0, 0, 255)' backgroundColor: 'rgb(0, 0, 255)'
}], }
]
}; };
const config = { const config = {
type: 'scatter', type: 'scatter',
@@ -31,7 +36,17 @@ class SymptomVsSymptomChartView {
scales: { scales: {
x: { x: {
type: 'linear', type: 'linear',
position: 'bottom' position: 'bottom',
title: {
display: true,
text: 'PRR ratio of Batch for ' + symptomX
}
},
y: {
title: {
display: true,
text: 'PRR ratio of Batch for ' + symptomY
}
} }
}, },
plugins: { plugins: {
@@ -48,16 +63,7 @@ class SymptomVsSymptomChartView {
} }
} }
}; };
this.#chart = new Chart( this.#chart = new Chart(this.#canvas, config);
this.#canvas,
// {
// type: 'bar',
// plugins: [ChartDataLabels],
// data: this.#getData(ADRDescr),
// options: this.#getOptions()
// }
config);
});
} }
setData(histoDescr) { setData(histoDescr) {