From fe2289fb39d1cbe80b4ff4da0acc009f88038e76 Mon Sep 17 00:00:00 2001 From: frankknoll Date: Sat, 28 Jan 2023 12:13:33 +0100 Subject: [PATCH] starting to fetch histogram data --- docs/batchCodeTable.js | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/docs/batchCodeTable.js b/docs/batchCodeTable.js index eabbd9c376d..b12f3f678f5 100644 --- a/docs/batchCodeTable.js +++ b/docs/batchCodeTable.js @@ -16,7 +16,7 @@ class BatchCodeTableInitializer { this.#countrySelect.addEventListener('change', event => this.#displayCountry(event.target.value)); this.#displayCountry('Global') // FK-TODO: refactor - function format(d) { + function createDiv() { const div = document.createElement("div"); const canvas = document.createElement("canvas"); canvas.setAttribute("id", "symptomByBatchcodeHisto"); @@ -34,23 +34,27 @@ class BatchCodeTableInitializer { row.child.hide(); tr.removeClass('shown'); } else { - const d = row.data(); - const data = JSON.parse(d[10]); - const div = format(d); + const div = createDiv(); row.child(div).show(); - new Chart( - div.querySelector('#symptomByBatchcodeHisto'), - { - type: 'bar', - data: { - datasets: [{ - label: 'Acquisitions by year', - data: data - }] - } - } - ); tr.addClass('shown'); + const batchcode = 'FD6840'; + fetch(`data/histograms/${batchcode}.json`) + .then(response => response.json()) + .then(json => { + const data = json.histograms[3].histogram; + new Chart( + div.querySelector('#symptomByBatchcodeHisto'), + { + type: 'bar', + data: { + datasets: [{ + label: 'Acquisitions by year', + data: data + }] + } + } + ); + }); } }); }