# My Y axis isn't showing a good scale

« Back to message list

« Back to message list

Having set the minimum and maximum Y values, I've now got 13, 19, 25, 30, 36, 41 as the Y-labels.

How do you show 15, 20, 25, 30, 35, 40 instead?

It should only show good numbers by default (eg. multiplies of 2, 5 or 10)

Posted by RGraph support on 26th November 2012How do you show 15, 20, 25, 30, 35, 40 instead?

It should only show good numbers by default (eg. multiplies of 2, 5 or 10)

If you have set the min and max values then you're probably not going to get a great scale. You could try the
following:

chart.ylabels.count - This allows you to set how many Y labels there are

chart.scale.decimals - This allows you to set how many decimals there are - you might get a more even scale if you set this to 1 or 2.

chart.ylabels.specific - This allows you set the Y labels exactly how you want

You may also be interested in the RGraph.DrawYAxis() function which you can read about here:

www.rgraph.net/canvas/docs/api.html

Posted by Aximili on 26th November 2012chart.ylabels.count - This allows you to set how many Y labels there are

chart.scale.decimals - This allows you to set how many decimals there are - you might get a more even scale if you set this to 1 or 2.

chart.ylabels.specific - This allows you set the Y labels exactly how you want

You may also be interested in the RGraph.DrawYAxis() function which you can read about here:

www.rgraph.net/canvas/docs/api.html

Ok, here is a function to determine the best Y-min, Y-max, and Y-count

if (max1 - min1 > 0) {

var interval = 1.0 * (max1 - min1) / MAX_Y_COUNT;

// Round up interval to (2, 5 or 10) * 10^x

var multiplier = 1;

while (interval / multiplier > 10)

multiplier *= 10;

var n = interval / multiplier;

if (n <= 1) n = 1;

else if (n <= 5) n = 5;

else n = 10;

interval = n * multiplier;

// Round down min1, round up max1

min1 = Math.floor(min1 / interval) * interval;

max1 = Math.ceil(max1 / interval) * interval;

yCount = (max1 - min1) / interval;

}

If in the graph has values ranging from 13 to 41, that function will set

min1 = 10

max1 = 50

yCount = 4

Then you do

line.Set('chart.ymin', min1);

line.Set('chart.ymax', max1);

line.Set('chart.ylabels.count', yCount);

That means it should show the values 10, 20, 30, 40, 50 (Yes it shows 6 numbers when you set the ylabels.count to 5)

That would be perfect, except RGraph is now complaining

[LINE SCALE] The number of Y labels must be 1/3/5/10

Why??? How do you force it to show 10,20,30,40,50?

Posted by Aximili on 26th November 2012if (max1 - min1 > 0) {

var interval = 1.0 * (max1 - min1) / MAX_Y_COUNT;

// Round up interval to (2, 5 or 10) * 10^x

var multiplier = 1;

while (interval / multiplier > 10)

multiplier *= 10;

var n = interval / multiplier;

if (n <= 1) n = 1;

else if (n <= 5) n = 5;

else n = 10;

interval = n * multiplier;

// Round down min1, round up max1

min1 = Math.floor(min1 / interval) * interval;

max1 = Math.ceil(max1 / interval) * interval;

yCount = (max1 - min1) / interval;

}

If in the graph has values ranging from 13 to 41, that function will set

min1 = 10

max1 = 50

yCount = 4

Then you do

line.Set('chart.ymin', min1);

line.Set('chart.ymax', max1);

line.Set('chart.ylabels.count', yCount);

That means it should show the values 10, 20, 30, 40, 50 (Yes it shows 6 numbers when you set the ylabels.count to 5)

That would be perfect, except RGraph is now complaining

[LINE SCALE] The number of Y labels must be 1/3/5/10

Why??? How do you force it to show 10,20,30,40,50?

Also, when ymin = 15, ymax = 30, I set count = 3

It should show 15, 20, 25, 30 - which would be perfect.

But RGraph is showing 15, 28, 24, 30 instead...???

Posted by RGraph support on 27th November 2012It should show 15, 20, 25, 30 - which would be perfect.

But RGraph is showing 15, 28, 24, 30 instead...???

Hi,

You can use chart.ylabels.specific for this.

You can use chart.ylabels.specific for this.

### Add a reply

« Back to message list

« Back to message list