1
votes

I have to render a chart using the Highcharts library, but I need the y axis to be logarithmic. This is easy to do by setting the yAxis type to logarithmic.

However, the ticks on the axis are powers of ten equally spaced : 0.01, 0.1, 1, 10, 100, ...

I would like exactly the same thing but in base 2: equally spaced ticks with the values written on the axis being powers of two : 0.5, 1, 2, 4, 8, 16, ...

If the number of ticks and the min and max values can adapt from the data (like the regular base 10 log scale), that would be great.

Any suggestions ? After crawling the web looking at logarithmic scenarios, I found nothing relevant to that problem.

Thanks!

1

1 Answers

5
votes

This would be a quick way to do it (JSFiddle):

Highcharts.Axis.prototype.log2lin = function (num) {
    return Math.log(num) / Math.LN2;
};

Highcharts.Axis.prototype.lin2log = function (num) {
    return Math.pow(2, num);
};

You might want to rewrite Axis.prototype.getLogTickPositions if you need minorTickInterval support.