1

I'm trying to reference a value which stores a model's property from the session.

var value = '${foo.property}';

Now using chartjs I try to reference the value as one of the data for the graph

 myChart = document.getElementById('myChart').getContext('2d');

         massPopChart = new Chart(myChart, {
             type: 'bar' ,
             data: {
                 labels:['Sample Column' , '2nd Low Value Column'],
                 datasets:[{
                     label: 'Sample Value Column',
                     data:[

               //------REFERENCE OVER HERE
                         value, 
                         3000
                     ],
                     backgroundColor:[
                         'rgba(255,99,132,0.6)',
                         'rgba(54,162,235,0.6)'
                     ]
                 }]
             }, 
             options:{}
         });

From inspecting elements the value I get is not the value of the model property but the word value itself

I've read up on javascript tutorials none of their lessons about variables help me with this issue

I learned that referencing variables in javascript is different so can someone enlighten me on this

EDIT: I've also tried directly referencing '${foo.property}' in the data segment and I get the value but it returns as a String, I have tried using parseInt and Number to try to convert but to no avail

3
  • Try var value = foo.property Commented May 21, 2019 at 6:12
  • Javascript and Java are completely different programming languages - please only use the correct tag. Commented May 21, 2019 at 6:49
  • it was related in a way(session variable was set using java servlets) but i'll take note of that when posting next time Commented May 21, 2019 at 7:48

1 Answer 1

1

Thanks to a comment from a certain user(who deleted it for some reason), I found that removing the quotes and directly referencing the model property in the data segment will do just what I need

 data:[
     ${foo.property} , //NOT '${foo.property}'
     3000
 ],

referencing a variable into the data segment still has that issue where the name of variable is what's used rather than the assigned value

Sign up to request clarification or add additional context in comments.

2 Comments

It’s not ’$(foo.property)’ if you look closer, it’s ‘${foo.property}’
:) Actually ‘${foo.prperty}’ is a string interpolation, and only useful if you place a variable inside a string. If there’s no string before and after it you don’t need it, foo.property is enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.