# Can you use a logarithmic scale on a gauge?

Share RGraph:

« Back to message list

Posted by Graeme Elsworthy on 5th September 2017
Hi Richard,

Is there a way I can create a Gauge chart with a logarithmic scale?

Cheers,
Graeme.
Posted by Richard on 5th September 2017
Hi there,

Yes - the Meter chart and the Gauge chart both support the labelsSpecific option.

www.rgraph.net/demos/meter-specific-labels.html
www.rgraph.net/canvas/docs/gauge.html#labelsSpecific

So using that you can use the RGraph API function to create a logarithmic scale in a similar way to these Bar/Line charts:

www.rgraph.net/demos/svg-line-logarithmic.html
www.rgraph.net/demos/bar-logarithmic-scale.html
www.rgraph.net/demos/line-logarithmic-scale.html

Eg This SVG Line chart code creates the data for the chart:

data = [0,10,0,100,0,1000,0,10000,0,100000];

for (var i=0; i<data.length; ++i) {
if (data[i] > 0) {
data[i] = RGraph.SVG.log({num:data[i], base: 10});
}
}

And in this case the Line chart has specific labels:

yaxisLabels:['0','10','100','1,000','10,000','100,000','1,000,000'],

Richard
Posted by Graeme Elsworthy on 5th September 2017
Thanks, Richard.
Posted by Graeme Elsworthy on 8th September 2017
Hi Richard,

Thanks for your help on logarithmic gauges, they have worked out really well, but they do present a bit of a challenge. For starters, on a logarithmic scale there is no zero and there are no negatives, but my gauges must show from large negative numbers to large positives. And, secondly, how to show the real value in the valueText field rather than the log of the value.

I solved the first problem with a slight-of-hand - I came up with a very small number which, if the real value is lower than, shows as the gauge's zero, and anything above shows as the log of the value. And if the real value is negative I simply invert the sign, take the log, invert the sign again and set this as the gauge's value. There is an offset problem that is easily fixed, but that is essentially it.

And to solve the second problem, showing the real value rather than the log of the real value, I created a new property: valueTextValue. If this is set then this is what is shown in the valueText area rather than chart.value.

Hope this makes sense.

Cheers,
Graeme.
Posted by Richard on 8th September 2017
Hi there,

> And to solve the second problem, showing the real value rather than the log of the real value, I created a new property:
> valueTextValue. If this is set then this is what is shown in the valueText area rather than chart.value.

Other charts use the name "specific" - so the property name would be:

valueTextSpecific

But yours works too! They do just what yours does though - they allow you to put your own bit of text in instead of the one generate by RGraph.

Richard
Posted by Graeme Elsworthy on 9th September 2017
Hi Richard,

I've changed the property name to valueTextSpecific.

Cheers,
Graeme.