92 lines
3.1 KiB
JavaScript
92 lines
3.1 KiB
JavaScript
//For now create dummy data to show on the website.
|
|
let awa;
|
|
|
|
data();
|
|
|
|
|
|
async function data() {
|
|
fetch("http://145.92.8.114/getQuestionData")
|
|
.then(response => {
|
|
if (!response.ok) {
|
|
throw new Error('Network response was not ok');
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(data => {
|
|
console.log(data);
|
|
|
|
// Initialize an array to hold the counts for each question
|
|
let questionCounts = [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]];
|
|
|
|
// Iterate over the data
|
|
for (let item of data) {
|
|
// Increment the count for the appropriate question and result
|
|
questionCounts[item.Question_QuestionID - 1][item.Result]++;
|
|
}
|
|
|
|
// Log the counts for each question
|
|
for (let i = 0; i < questionCounts.length; i++) {
|
|
console.log(`Question ${i + 1} counts: ${questionCounts[i]}`);
|
|
}
|
|
|
|
// Update the dummydata arrays
|
|
dummydata1 = questionCounts[0];
|
|
dummydata2 = questionCounts[1];
|
|
dummydata3 = questionCounts[2];
|
|
dummydata4 = questionCounts[3];
|
|
dummydata5 = questionCounts[4];
|
|
|
|
graph();
|
|
})
|
|
}
|
|
// for each(Result == 0) in
|
|
async function graph() {
|
|
let questionOptionsDummy1 = ['clean','fine', 'disgusting'];
|
|
|
|
let questionOptionsDummy2 = ['clean', 'normal', 'disgusting'];
|
|
|
|
let questionOptionsDummy3 = ['hot', 'perfect', 'cold'];
|
|
|
|
let questionOptionsDummy4 = ['not at all', 'its fine', 'really crowded', ];
|
|
|
|
let questionOptionsDummy5 = ['no','decently', 'yes'];
|
|
|
|
//make arrays to store data.
|
|
let chartConfigArray = [];
|
|
let textArray = [];
|
|
|
|
let questionArray = [];
|
|
let questionOptionsDummy = [];
|
|
let dummydata = [];
|
|
|
|
//Go along the array's to fetch data, and push this in a class.
|
|
for (let i = 0; i < 5; i++) {
|
|
dummydata.push(dummydata1, dummydata2, dummydata3, dummydata4, dummydata5);
|
|
questionOptionsDummy.push(questionOptionsDummy1, questionOptionsDummy2, questionOptionsDummy3, questionOptionsDummy4, questionOptionsDummy5);
|
|
|
|
questionArray.push(new QuestionCreationClass(dummydata[i], questionOptionsDummy[i]));
|
|
}
|
|
|
|
//Go allong another array to also give the class that creates the charts the data collected by the previous array.
|
|
for (let i = 0; i < 5; i++){
|
|
textArray.push('Question 1 Responses', 'Question 2 Responses', 'Question 3 Responses', 'Question 4 Responses', 'Question 5 Responses');
|
|
|
|
chartConfigArray.push(new ChartConfigClass(questionArray[i].questionData, textArray[i]));
|
|
}
|
|
|
|
// Create the charts
|
|
const ctx1 = document.getElementById('chart1').getContext('2d');
|
|
const myChart1 = new Chart(ctx1, chartConfigArray[0].chartConfig);
|
|
|
|
const ctx2 = document.getElementById('chart2').getContext('2d');
|
|
const myChart2 = new Chart(ctx2, chartConfigArray[1].chartConfig);
|
|
|
|
const ctx3 = document.getElementById('chart3').getContext('2d');
|
|
const myChart3 = new Chart(ctx3, chartConfigArray[2].chartConfig);
|
|
|
|
const ctx4 = document.getElementById('chart4').getContext('2d');
|
|
const myChart4 = new Chart(ctx4, chartConfigArray[3].chartConfig);
|
|
|
|
const ctx5 = document.getElementById('chart5').getContext('2d');
|
|
const myChart5 = new Chart(ctx5, chartConfigArray[4].chartConfig);
|
|
} |