Finally extracting questions from the survey. Additional table added to hold questions
This commit is contained in:
44
drawbar.js
44
drawbar.js
@@ -28,7 +28,8 @@ SOFTWARE.
|
||||
|
||||
|
||||
function drawBar(id,data) {
|
||||
//console.log(id);
|
||||
console.log(id);
|
||||
console.log(data);
|
||||
const svg = d3.select(`${id}`);
|
||||
const backgroundwidth = +svg.attr("width");
|
||||
const backgroundradius = 10;
|
||||
@@ -276,7 +277,46 @@ return average; //Needed for the next layer up in the analysis
|
||||
|
||||
|
||||
|
||||
function doBarData(id,qid) {
|
||||
function doBarData(id,qid, survey, Q1=0, Q2=0, Q3=0 ) {
|
||||
// Create the form data object
|
||||
const formData = new FormData();
|
||||
formData.append('qid', qid);
|
||||
formData.append('survey', survey);
|
||||
formData.append('Q1', Q1);
|
||||
formData.append('Q2', Q2);
|
||||
formData.append('Q3', Q3);
|
||||
|
||||
// Send the form data using fetch
|
||||
fetch('get_qid_counts.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.text())
|
||||
.then(data => {
|
||||
// Output result
|
||||
console.log(data);
|
||||
const parsed = JSON.parse(data);
|
||||
|
||||
// 2. Clean the keys and build a usable object
|
||||
const bardata = {};
|
||||
parsed.forEach(entry => {
|
||||
const rawKey = Object.keys(entry)[0];
|
||||
const cleanKey = rawKey.replace(/"/g, ''); // Remove extra quotes
|
||||
bardata[cleanKey] = entry[rawKey];
|
||||
});
|
||||
|
||||
console.log(bardata);
|
||||
drawBar(id,bardata);
|
||||
// return data; // Should be an array like [{ value: -3, count: 2 }, ..., { value: 3, count: 5 }]
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function Backup() {
|
||||
return fetch('get_qid_counts.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
|
||||
Reference in New Issue
Block a user