Skip to content

Commit e462005

Browse files
committed
retrieves answers from custom question API
1 parent eff7b44 commit e462005

File tree

3 files changed

+65
-57
lines changed

3 files changed

+65
-57
lines changed

data.js

Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,70 @@
11
import Chart from "chart.js/auto";
22
import {
3-
getAnswerValue,
4-
setAnswerValue,
3+
getAllAnswerValues,
54
setAutoHeight
65
} from "@formsort/custom-question-api";
76

8-
// Need a function that can transform: current weight, weight loss time horizon into a data object
9-
const allAnswers = getAnswerValue();
7+
// Need a function that can transform: current weight, goal weight, and weight loss time horizon into a fields for data.datasets.data
8+
async function getAllAnswers() {
9+
const answers = await getAllAnswerValues();
10+
const values = Object.values(answers);
1011

11-
(async function () {
12-
const ctx = document.getElementById("data");
12+
console.log(`values: ${values}`);
13+
}
14+
getAllAnswers();
1315

14-
const data = [
15-
{ month: "Jan", weight: 250 },
16-
{ month: "Feb", weight: 250 },
17-
{ month: "Jun", weight: 200 }
18-
];
19-
20-
new Chart(ctx, {
21-
type: "line",
22-
options: {
23-
pointStyle: false,
24-
fill: true,
25-
backgroundColor: "rgb(229,229,229,0.8)",
26-
borderColor: "#00000",
27-
borderWidth: 3,
28-
scales: {
29-
x: {
30-
type: "category",
31-
max: 2,
32-
labels: ["January", "February", "March", "April", "May"],
33-
// min: "February",
34-
grid: {
35-
display: false
36-
}
37-
},
38-
y: {
39-
grid: {
40-
display: false
41-
},
42-
ticks: {
43-
count: 2
44-
}
45-
}
16+
const options = {
17+
pointStyle: false,
18+
fill: true,
19+
backgroundColor: "rgb(229,229,229,0.8)",
20+
borderColor: "#00000",
21+
borderWidth: 3,
22+
scales: {
23+
x: {
24+
// type: "time",
25+
max: 2,
26+
labels: ["January", "February", "March", "April", "May"],
27+
// min: "February",
28+
grid: {
29+
display: false
4630
},
47-
plugins: {
48-
legend: {
49-
display: false
50-
}
31+
ticks: {
32+
align: "start",
33+
crossAlign: "far",
34+
count: 2
5135
}
5236
},
53-
data: {
54-
datasets: [
55-
{
56-
data: data.map((row) => row.weight)
57-
}
58-
]
37+
y: {
38+
grid: {
39+
display: false
40+
},
41+
ticks: {
42+
count: 2,
43+
crossAlign: "near"
44+
}
45+
}
46+
},
47+
plugins: {
48+
legend: {
49+
display: false
5950
}
51+
}
52+
};
53+
54+
const data = {
55+
datasets: [
56+
{
57+
data: [300, 300, 200]
58+
}
59+
]
60+
};
61+
62+
(async function () {
63+
const ctx = document.getElementById("data");
64+
65+
new Chart(ctx, {
66+
type: "line",
67+
data: data,
68+
options: options
6069
});
6170
})();

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"snowpack": "^3.8.8"
1313
},
1414
"dependencies": {
15-
"@cubejs-client/core": "^0.31.0",
1615
"@formsort/custom-question-api": "^0.3.3",
1716
"chart.js": "^4.0.0"
1817
}

snowpack.config.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const fs = require("fs");
1+
// const fs = require("fs");
22

3-
const cert = fs.readFileSync("./localhost.cert");
4-
const key = fs.readFileSync("./localhost.key");
3+
// const cert = fs.readFileSync("./localhost.cert");
4+
// const key = fs.readFileSync("./localhost.key");
55

6-
module.exports = {
7-
devOptions: {
8-
secure: { cert, key }
9-
}
10-
};
6+
// module.exports = {
7+
// devOptions: {
8+
// secure: { cert, key }
9+
// }
10+
// };

0 commit comments

Comments
 (0)