RGraph is a JavaScript charts library based on HTML5 SVG and canvas. RGraph is mature (over 15 years old) and has a wealth of features making it an ideal choice to show charts on your website.

More »


Get the latest version of RGraph (version 6.17) from the download page. There's also older versions available, minified files and links to cdnjs.com hosted libraries.

More »


RGraph can be used for free under the GPL or if that doesn't suit your situation there's an inexpensive (£99) commercial license available.

More »

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]