Negative values are scaled incorrectly on the Line chart

Share RGraph:   Share or Like RGraph on Facebook!

« 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 Othmar on 27th December 2015
Hello

If i have only negative values and the zero line is on top the line graph is scaled incorrect.
Look here: jsfiddle.net/px6n6Le9/1/
(red line)
I use "outofbounds" option. I also have tested "xaxispos" option.
If a positive value is included, it's correct.
Look here: jsfiddle.net/px6n6Le9/2/

It looks like a zero value of max does not work.

Thank you
othmar
Posted by Richard on 27th December 2015
Hi there,

It all looks fine. Do you want to see 0 at the top? If so you'll need to set the xaxispos option to top.





Richard
Posted by Othmar on 27th December 2015
Hello Richard

It not looks fine ;-) Look at the red line. 0 is on top but scaling ist on center.

On this test the ymax value is 0 but was displayed 5
jsfiddle.net/dwdsgeae/1/

If i use xaxispos it was totally cracy
jsfiddle.net/d4hrc2tt/1/

Seems ymax as zero did not work. If i use 0.1 it is ok - but is not 0 ...
jsfiddle.net/dwdsgeae/3/
Posted by Richard on 27th December 2015
Hi,

The ymax and ymin are not meant to be used as absolute values. The system isn't the most intuitive perhaps. Try this:

var line = new RGraph.Line({
   id: 'cvs',
   data: [1, 2, 1, 3, 1], // Note: Positive values though they're displayed as negative
   options: {
     noxaxis: true,
     xaxispos: 'top',
     ymax: 5,
     linewidth: 2,
     backgroundGrid: true,
     colors: ['rgba(255,0,0,1)'],
     shadowColor: ['rgba(190,0,0,0.5)'],
     tooltips: ["-1", "-2", "-1", "-3", "-1"],
     gutterLeft: 80
   }
}).draw();


Richard
Posted by Othmar on 27th December 2015
Hi Richard

In my case the values are temperatures. They are from am database. I can't switch all values to positive.
The vallues are all dynamically. Min and max also calculated from the database.
Have found a workaround:
jsfiddle.net/dwdsgeae/4/
I set the max value to -0.00000000000000001

But i think its a bug because 0.0 did not work.

Othmar
Posted by Richard on 27th December 2015
Hi,

> In my case the values are temperatures. They are from am database. I can't switch all
> values to positive.
> The vallues are all dynamically. Min and max also calculated from the database.

I don't see why that makes a difference. For example you can change the data before you give it to RGraph instead of giving it directly to RGraph:



var data = [<?php echo implode($values) ?>];

for (var i=0; i<data.length; ++i) {
     data[i] = Math.abs(data[i]);
}

Then you can use the data variable in your chart:

var line = new RGraph.Line({
     id: 'cvs',
     data: data,
     options: {
         // ...






Richard
Posted by Othmar on 28th December 2015
Hi

It's easier to use the workaround with -0.00000000000000001 value. In this case the axis it set automatically to top, center and bottom. If i have convert the values to positiv, i have to check alltimes if values greater, lower or arround 0. Then i have to convert the data and set the axis.

For my case my workaround works well, but in some other cases (some other usere) it can be a problem.
A ymax with value 0 is easier as someone convert the complete data.
Probably its only a if == 0 in the code instead if === 0 .....
Posted by temperatures graths on 26th February 2016
Basicaly I have the same problem
Why not setting the zero axes position in proportion to min/max values and number of ticks
then plotting values directly ?

the different twickings to get there look very complicated

Am I missing something ? or not using the proper library ?
I use Rgrath.line.js
Thanks
Posted by Richard on 27th February 2016
Hi,

The axes were first designed (some time ago) to have the X axis in the center. There are examples of having offset axes in the demos but its not a small amount of code. It's easier if you have the X axis at the bottom and use the ymin/ymax settings to control the scale like this:

www.rgraph.net/fiddle/view.html/multiple-lines-with-a-scale-with-negatives

Currently you need to redefine the window.alert() function to avoid an alert(), but you won't when the next release of RGraph is available.






Richard

Add a reply




« Back to message list