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

Share RGraph:   To help my Google visibility (it can't get much worse!), if you like and use RGraph I'd appreciate it if you could link to me

« 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.

ex.
   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
Hi,

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

For example on this page:

www.rgraph.net/fiddle/view.html/a-simple-grouped-bar-chart

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.

Richard
If RGraph has helped you - please share the website and give your feedback - thanks! You can give your feedback or leave a testimonial by adding a forum post
Posted by Richard on 25th September 2015
Hi,

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.

Richard
If RGraph has helped you - please share the website and give your feedback - thanks! You can give your feedback or leave a testimonial by adding a forum post
Posted by Jason on 25th September 2015
Thanks so much for the quick reply!

~Jason

Add a reply




« Back to message list