How do I dynamically assign labels from a variable?

Posted by Roberto at 15:25 on Tuesday 20th April 2021 [link]
I would like to know how to pass a string or array dynamically to assign values to the xaxisLabels variable. For example if I wanted to assign a variable

xaxisLabels: ["Tue", "Wed", "Thu"]

and then I do:

var value = "Tue, Wed, Thu";
and then:
xaxisLabels: [value],
it doesn't work. How can I solve

Posted by Richard at 22:22 on Tuesday 20th April 2021 [link]
Well, if what you want is just to use your "value" variable as the xaxisLabels then you could do this:

// Split the string into an array accounting for
// there being zero or more space characters either
// side of the comma.
var value = "Tue, Wed, Thu".split(/ *, */);

// And then in your chart configuration add this:
xaxisLabels: value,

Though a better name for the variable might be "labels".

[Replies are now closed]