@@ -5,12 +5,12 @@ import {
55} from "@formsort/custom-question-api" ;
66
77async function loadClientConfig ( ) {
8- const urlParams = new URLSearchParams ( window . location . search ) ;
9- const answerLabel = urlParams . get ( ' answerLabel' ) ;
8+ const urlParams = new URLSearchParams ( window . location . search ) ;
9+ const answerLabel = urlParams . get ( " answerLabel" ) ;
1010
11- const answers = await getAllAnswerValues ( ) ;
11+ const answers = await getAllAnswerValues ( ) ;
1212
13- return answers [ answerLabel ] || { } ;
13+ return answers [ answerLabel ] || { } ;
1414}
1515
1616/**
@@ -27,15 +27,6 @@ async function loadClientConfig() {
2727 * }
2828 */
2929
30- // Need a function that can transform: current weight, goal weight, and weight loss time horizon into a fields for data.datasets.data
31- async function getAllAnswers ( ) {
32- const answers = await getAllAnswerValues ( ) ;
33- const values = Object . values ( answers ) ;
34-
35- console . log ( `values: ${ values } ` ) ;
36- }
37- getAllAnswers ( ) ;
38-
3930const options = {
4031 pointStyle : false ,
4132 fill : true ,
@@ -44,17 +35,11 @@ const options = {
4435 borderWidth : 3 ,
4536 scales : {
4637 x : {
47- // type: "time",
48- max : 2 ,
49- labels : [ "January" , "February" , "March" , "April" , "May" ] ,
50- // min: "February",
5138 grid : {
5239 display : false
5340 } ,
5441 ticks : {
55- align : "start" ,
56- crossAlign : "far" ,
57- count : 2
42+ display : false
5843 }
5944 } ,
6045 y : {
@@ -74,26 +59,40 @@ const options = {
7459 }
7560} ;
7661
77- const defaultData = {
78- datasets : [
79- {
80- data : [ 300 , 300 , 200 ]
81- }
82- ]
83- } ;
62+ // const defaultData = {
63+ // datasets: [
64+ // {
65+ // data: [1, 10 ]
66+ // }
67+ // ]
68+ // };
8469
8570( async function ( ) {
86- const { data = defaultData , labels } = await loadClientConfig ( ) ;
71+ const result = await loadClientConfig ( ) ;
8772
88- if ( labels ) {
89- options . scales . x . labels = labels ;
90- }
73+ const res = await getAllAnswerValues ( ) ;
74+ const clientConfig = await loadClientConfig ( ) ;
75+
76+ console . log ( res ) ;
77+ console . log ( clientConfig ) ;
78+
79+ // chart_data will have labels hard-coded in
80+ // if (labels) {
81+ // options.scales.x.labels = labels;
82+ // }
9183
9284 const ctx = document . getElementById ( "data" ) ;
9385
9486 new Chart ( ctx , {
9587 type : "line" ,
96- data : data ,
97- options : options
88+ options : options ,
89+ data : {
90+ labels : result . map ( ( item ) => item . labels ) ,
91+ datasets : [
92+ {
93+ data : result . map ( ( item ) => item . data )
94+ }
95+ ]
96+ }
9897 } ) ;
9998} ) ( ) ;
0 commit comments