MENU
.net Powerful JavaScript charts
About
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 use for showing charts on your website.

More »

 

Download
Get the latest version of RGraph (version 6.18, 1st June 2024) from the download page. You can read the changelog here. There's also older versions available, minified files and links to cdnjs.com hosted libraries.

More »

 

License
RGraph can be used for free under the GPL or if that doesn't suit your situation there's an inexpensive (£129) 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]
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 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 closed]