Chartjs-Complex Javascript variables containing the values of other assigned variables?

1👍

Your syntax won’t work in your first example in a couple places. There are some great tutorials out there. Most of your issues above come from the fact that you’re not assigning everything in your object to a key.

For example, you have a pattern of

var myObject = {
    thing1: 'thing one',
    {
        thing2: 'thing two',
    }, // etc
}

After the first comma, on the same line as 'thing one', you start another object. You need to assign that object to a key in the parent object.

var myObject = {
    thing1: 'thing one',
    secondObject: {
        thing2: 'thing two',
    }, // etc
}

But like I said, there are tons of resources out there for beginner JS. I’d start there before posting to SO.

0👍

Yes. The right-hand side of a name: property pair in an object literal just needs to be an expression.

Your problems are caused by typos, not by the use of variables.


  • JavaScript is case sensitive. myData and mydata are different variable names
  • Variable assignments use =, not :
  • Objects are constructed of property: value separated by commas. You forgot the property: part sometimes and just had a value.
var abc = "123";
var myData = [123, 45, 67, 78, 89, 123];

var verycomplexstruct = {
  this: abc,
  something: {
    that: myData, 
    something_else: {}
  }
};

console.log(verycomplexstruct);

Leave a comment