Add chart for int responses

This commit is contained in:
nemunaire 2022-05-01 13:06:58 +02:00
parent 2c66c58d4f
commit 41df85c33b
2 changed files with 21 additions and 3 deletions

View File

@ -17,7 +17,7 @@
proposal_idx[proposal.id] = new String(data.labels.length - 1); proposal_idx[proposal.id] = new String(data.labels.length - 1);
} }
req_responses = refreshResponses(); req_responses = question.getResponses();
req_responses.then((responses) => { req_responses.then((responses) => {
for (const res of responses) { for (const res of responses) {
data.datasets[0].values[proposal_idx[res.value]] += 1; data.datasets[0].values[proposal_idx[res.value]] += 1;
@ -27,9 +27,27 @@
return req; return req;
} }
let req_proposals = refreshProposals(); let req_proposals = null;
let req_responses = null; let req_responses = null;
if (question.kind == "int") {
req_responses = question.getResponses();
req_responses.then((responses) => {
const proposal_idx = { };
for (const res of responses) {
if (proposal_idx[res.value]) {
data.datasets[0].values[proposal_idx[res.value]] += 1;
} else {
data.labels.push(res.value);
data.datasets[0].values.push(1);
proposal_idx[res.value] = new String(data.labels.length - 1);
}
}
});
} else {
req_proposals = refreshProposals();
}
let data = { let data = {
labels: [], labels: [],
datasets: [ datasets: [

View File

@ -108,7 +108,7 @@
{/if} {/if}
</button> </button>
{/if} {/if}
{#if question.kind == "ucq" || question.kind == "mcq"} {#if question.kind == "ucq" || question.kind == "mcq" || question.kind == "int"}
<button <button
type="button" type="button"
class="btn btn-sm float-end mx-1" class="btn btn-sm float-end mx-1"