|
1 | 1 | import Chart from "chart.js/auto"; |
2 | 2 | import { |
3 | | - getAnswerValue, |
4 | | - setAnswerValue, |
| 3 | + getAllAnswerValues, |
5 | 4 | setAutoHeight |
6 | 5 | } from "@formsort/custom-question-api"; |
7 | 6 |
|
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); |
10 | 11 |
|
11 | | -(async function () { |
12 | | - const ctx = document.getElementById("data"); |
| 12 | + console.log(`values: ${values}`); |
| 13 | +} |
| 14 | +getAllAnswers(); |
13 | 15 |
|
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 |
46 | 30 | }, |
47 | | - plugins: { |
48 | | - legend: { |
49 | | - display: false |
50 | | - } |
| 31 | + ticks: { |
| 32 | + align: "start", |
| 33 | + crossAlign: "far", |
| 34 | + count: 2 |
51 | 35 | } |
52 | 36 | }, |
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 |
59 | 50 | } |
| 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 |
60 | 69 | }); |
61 | 70 | })(); |
0 commit comments