Problem with integer Y axis labels

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 Helio on 24th March 2017
Hi!

I got the following graph:

The YAxis values is set for 5 values, but considering a maxY of 12, each gridline is set for 2,40 (12/5).

When I set the labels for scaleDecimals = 0, it just rounds the labels values, but the bar size gets inconsistent with the label value.

Is there any way to recalculate everything based on those rounded yLabels?


var GH_WEEKLY = new RGraph.Bar('GH_WEEKLY', [[4], [4], [7]]);
GH_WEEKLY.Set('tooltips', ['']);
GH_WEEKLY.Set('chart.background.barcolor1', '#F5F5F5');
GH_WEEKLY.Set('chart.background.barcolor2', '#F5F5F5');
GH_WEEKLY.Set('chart.gutter.bottom', 20);
GH_WEEKLY.Set('chart.gutter.top', 20);
GH_WEEKLY.Set('chart.key.position', 'gutter');
GH_WEEKLY.Set('chart.scale.point', ',');
GH_WEEKLY.Set('chart.scale.thousand', '.');
GH_WEEKLY.Set('chart.text.color', '#ff0000');
GH_WEEKLY.Set('chart.text.size', 9);
GH_WEEKLY.Set('chart.ymax', 12);
GH_WEEKLY.Set("numyticks", 5);
GH_WEEKLY.Set("ylabelsCount", 5);
GH_WEEKLY.Set('colors', ['rgba(237, 125, 49, 1)', 'rgba(237, 125, 49, 1)']);
GH_WEEKLY.Set('hmargin', 10);
GH_WEEKLY.Set('chart.scaleDecimals', 0); // <- If it goes to 1, the positions make sense
GH_WEEKLY.Set('shadow', true);
GH_WEEKLY.Set('shadow.offsetx', 0);
GH_WEEKLY.Set('shadow.offsety', 0);
GH_WEEKLY.Set('strokestyle', 'white');
GH_WEEKLY.Draw();

I just created a fiddle:
jsfiddle.net/heliogabrenha/urs69v61/

Thanks!
Posted by Richard on 25th March 2017
Hi there,

You could use 6 Y labels so you don't then need decimals:


GH_WEEKLY.Set('ylabelsCount', 6);
GH_WEEKLY.Set('backgroundGridAutofitNumhlines', 6);
GH_WEEKLY.Set('numyticks', 6);




Richard
Posted by Helio on 27th March 2017
I did that as a workaround, but the graph data is generated randomly, so fixing the number of grid lines won't always solve the problem.

Isn't there any way to recalculate the canvas considering the actual number of hgrid lines?

Thanks for replying!
Posted by Richard on 27th March 2017
Hi,

Afraid not - you'll need to test your data first and then configure RGraph appropriately. ie If you have data appropriate for 6 grid lines/labels do it that way, otherwise stick with 5.





Richard

Add a reply




« Back to message list