Chart.js: Radar charts need a logarithmic scale type option

Created on 27 Apr 2016  Â·  6Comments  Â·  Source: chartjs/Chart.js

For the same reasons it's needed in bar and line/scatter. Maybe there's a way to do that already? Tried a ticks callback from line, bar but couldn't make it work. Option for scale type with defaults as for line, bar would be easier.
radialdiagram

enhancement

Most helpful comment

I was able to cheat a logarithmic scale doing the following:

So on the data, before I gave it to the chart, I used

Math.log(data) / Math.log(2)

Then in the chart options (edited for brevity), I did….

options: {
scale: {

ticks: {
userCallback: function (value, index, values) {
Math.round(Math.pow(2,value)); //SO this will make the scale a logrithmic
},
}
},
tooltips: {
callbacks: {
label: function(tooltipItems, data) {
return fullLabelArray[tooltipItems.index] +': ' + Math.pow(2,tooltipItems.yLabel).toFixed(2); //This will make the tooltip data back to the original value
}
}
}

Just posting this in case it will help someone in the future.

All 6 comments

@norrhult you could implement this yourself. V2 allows custom scale creation. I'll try and find time to create a fiddle as a starting point

Thanks.
I doubt I have the skills to make it work but of course I'll give it a
try based on the starting point.
/Paul

On 2016-04-27 12:55, Evert Timberg wrote:

@norrhult https://github.com/norrhult you could implement this
yourself. V2 allows custom scale creation. I'll try and find time to
create a fiddle as a starting point

—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/chartjs/Chart.js/issues/2390#issuecomment-215048698


This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

@norrhult You could do start with https://github.com/chartjs/Chart.js/blob/master/src/scales/scale.radialLinear.js and extend out a new class that replaces a single function getDistanceFromCenterForValue with one that does logarithmic interpolation.

Some docs on writing scales is at http://www.chartjs.org/docs/#advanced-usage-writing-new-scale-types

Closing since we won't support this in the core. The recommended solution would be to create a new scale per my previous comment.

Thanks again for response and help.

I will pursue getting help from other users to make a new scale acc. to
your comment.

For the record, a user perspective: I think it should be part of core,
since anyone doing serious work with charts, and particularly scatter
charts, will want to use log as often as linear scale. Not all users are
programmers though.

/Paul

On 2016-05-26 00:10, Evert Timberg wrote:

Closing since we won't support this in the core. The recommended
solution would be to create a new scale per my previous comment.

—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/chartjs/Chart.js/issues/2390#issuecomment-221723045

Paul DeVries
White Pine Consulting
paul.devries.[email protected]
+46 704233952
skype: paul_devries


This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

I was able to cheat a logarithmic scale doing the following:

So on the data, before I gave it to the chart, I used

Math.log(data) / Math.log(2)

Then in the chart options (edited for brevity), I did….

options: {
scale: {

ticks: {
userCallback: function (value, index, values) {
Math.round(Math.pow(2,value)); //SO this will make the scale a logrithmic
},
}
},
tooltips: {
callbacks: {
label: function(tooltipItems, data) {
return fullLabelArray[tooltipItems.index] +': ' + Math.pow(2,tooltipItems.yLabel).toFixed(2); //This will make the tooltip data back to the original value
}
}
}

Just posting this in case it will help someone in the future.

Was this page helpful?
0 / 5 - 0 ratings