The RGraph.numberFormat() function doesn't handle negative values correctly when deciding if a thousands separator is necessary

« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Jason on 25th September 2015
Using the RGraph4.31 version (version: 2015-07-24).

Have found an issue with negative values in the RG.number_format() function defined in the RGraph.common.core.js file.

When provided a negative number of at least '-100', it treats this case as though it requires a thousand separator.

   where obj = RGraph.Drawing.XAxis
   RG.numberFormat(obj, -100) => '-,100'

The local fix I've employed is the following:

var ma = Math;

// Ignore the preformatted version of "1e-2"
if (String(num).indexOf('e') > 0) {
    return String(prepend + String(num) + append);

// [jtm 20150916] Negative Number Fix
// See if we have a negative number, if so strip the negative off to handle adding
// the thousand seperators appropriatly.
var sign = String(num).charAt(0) === '-' ? '-' : '';
num = ma.abs(num);

// We need then number as a string
num = String(num);


// [jtm 20150916] Negative Number Fix at the very end of the function
return sign + prepend + output + append;
Posted by Richard on 25th September 2015

Odd. It seems to be evident based on which type of object that you use.

For example on this page:


It works as expected if you pass it the bar object - but not if you use the xaxis object.

So maybe I haven't defined a required property on the xaxis object/ I'll take a look at it - thanks for that.

Posted by Richard on 25th September 2015

Indeed it seems to be a missing default. In your RGraph.drawing.xaxis.js file add these default properties (there's a list of defaults near the top of the file):

'chart.scale.decimals': 0,
'chart.scale.point': '.',

Which seems to resolve the issue.

Posted by Jason on 25th September 2015
Thanks so much for the quick reply!


Add a reply

« Back to message list