-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added in a visual chart to show questions and a admin function to delete users and update to admin
- Loading branch information
1 parent
101387c
commit ed038cf
Showing
10 changed files
with
323 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
const ctx = document.getElementById('myChart').getContext('2d'); | ||
|
||
const url = 'http://localhost:3000/api/getanswers'; | ||
|
||
fetch(url) | ||
.then(response => response.json()) | ||
.then(data => { | ||
console.log(data); | ||
setUpPieChart(data.labels, data.data); | ||
}); | ||
|
||
|
||
const setUpBarChart = (labels, data) => { | ||
const myChart = new Chart(ctx, { | ||
type: 'bar', | ||
data: { | ||
labels: labels, | ||
datasets: [{ | ||
label: '# of Votes', | ||
data: data, | ||
backgroundColor: [ | ||
'rgba(255, 99, 132, 0.2)', | ||
'rgba(54, 162, 235, 0.2)', | ||
'rgba(255, 206, 86, 0.2)', | ||
'rgba(75, 192, 192, 0.2)', | ||
'rgba(153, 102, 255, 0.2)', | ||
'rgba(255, 159, 64, 0.2)' | ||
], | ||
borderColor: [ | ||
'rgba(255, 99, 132, 1)', | ||
'rgba(54, 162, 235, 1)', | ||
'rgba(255, 206, 86, 1)', | ||
'rgba(75, 192, 192, 1)', | ||
'rgba(153, 102, 255, 1)', | ||
'rgba(255, 159, 64, 1)' | ||
], | ||
borderWidth: 1 | ||
}] | ||
}, | ||
options: { | ||
scales: { | ||
y: { | ||
beginAtZero: true | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
const setUpPieChart = (labels, data) => { | ||
const myChart = new Chart(ctx, { | ||
type: 'doughnut', | ||
data :{ | ||
labels: [ | ||
'Red', | ||
'Blue', | ||
'Green', | ||
'Dog', | ||
'Cat', | ||
'Fish', | ||
'Pizza', | ||
'Pasta', | ||
'Sushi' | ||
], | ||
datasets: [{ | ||
label: labels, | ||
data: data, | ||
backgroundColor: [ | ||
'rgb(255, 99, 132)', | ||
'rgb(54, 162, 235)', | ||
'rgb(3, 252, 3)', | ||
'rgb(75, 192, 192)', | ||
'rgb(153, 102, 255)', | ||
'rgb(255, 159, 64)', | ||
'rgb(255, 205, 86)', | ||
'rgb(7, 3, 252)', | ||
'rgb(252, 3, 3)' | ||
], | ||
hoverOffset: 4 | ||
}] | ||
}, | ||
options: { | ||
scales: { | ||
y: { | ||
beginAtZero: true | ||
} | ||
} | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
|
||
const dal = require('../data/mongoDAL'); | ||
|
||
router.get("/", (req, res) => { | ||
var resultJson = { | ||
data: [ | ||
{ | ||
name: "Ark", | ||
likes: 50 | ||
} | ||
] | ||
} | ||
res.json(resultJson); | ||
}); | ||
|
||
router.get("/getanswers", async (req, res) => { | ||
let answerToQuestion = await dal.findQuestions(); | ||
let red = 0; | ||
let blue = 0; | ||
let green = 0; | ||
let dog = 0; | ||
let cat = 0; | ||
let fish = 0; | ||
let pizza = 0; | ||
let pasta = 0; | ||
let sushi = 0; | ||
|
||
for(let i = 0; i < answerToQuestion.length; i++){ | ||
for(let j = 0; j < answerToQuestion[i].questions.length; j++){ | ||
switch(answerToQuestion[i].questions[j]){ | ||
case "red": red++; break; | ||
case "blue": blue++; break; | ||
case "green": green++; break; | ||
case "dog": dog++; break; | ||
case "cat": cat++; break; | ||
case "fish": fish++; break; | ||
case "pizza": pizza++; break; | ||
case "pasta": pasta++; break; | ||
case "sushi": sushi++; break; | ||
default: break; | ||
} | ||
} | ||
} | ||
|
||
var resultJson = { | ||
labels: ["Red", "Blue", "Green", "Dog", "Cat", "Fish", "Pizza", "Pasta", "Sushi"], | ||
data: [red, blue, green, dog, cat, fish, pizza, pasta, sushi] | ||
} | ||
res.json(resultJson); | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.