[RGRAPH SUPPORT] How do I dynamically assign labels from a variable?

How do I dynamically assign labels from a variable?

Post a reply
Posted by Roberto at 15:25 on 20th April 2021
Hello,
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 20th April 2021
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".

Post a reply

What's your name?
What do you want to say?