jays112
Posts: 4
Joined: Thu Mar 10, 2011 4:14 pm

Log axis Support - A Solution

Here's how a graph could be made using log-log axis:

First, create a function inside the "new Highcharts.Chart", as this:

Code: Select all

function logFunc(x) {
	return Math.log(x) / Math.log(10);		
};
Now add this code on both xAxis and yAxis:

Code: Select all

labels: {
	formatter: function() {
	        return Math.ceil(Math.pow(10,this.value));
	     }
}
Add this as a tooltip:

Code: Select all

tooltip: {
      formatter: function() {
           return '<b>'+ this.series.name +'</b><br/>'+
           (Math.pow(10,this.x)).toFixed(3) + 'X-data' + ': ' + (Math.pow(10,this.y)).toFixed(3) + 'Y-data';
      }
}
Final step, when you add your data, include them inside the logFunc function:

Code: Select all

series: [{
	name: 'MyData',
	data: [[logFunc(10),logFunc(20)], [logFunc(11),logFunc(22)]]
}]
The above code works fine, but an important thing to add is the corret axis grid, which should be a log-log grid.

Two more things to add:
1) grid theme with dotted lines
2) this.series.point.value

Hopefully they will be implemented soon on a new version!
torstein.honsi
Site Admin
Posts: 9215
Joined: Thu Nov 09, 2006 11:22 am
Location: Vik i Sogn, Norway

Re: Log axis Support - A Solution

Thanks for your contribution! Hopefully this will provide a quick hack for those waiting for a full implementation.
Torstein Hønsi
CTO, Founder
Highsoft
tpg
Posts: 2
Joined: Fri Apr 08, 2011 6:28 pm

Re: Log axis Support - A Solution

How could we add scales that looks like these...
axismode_2a.gif
axismode_2a.gif (7.05 KiB) Viewed 1512 times
hfrntt
Posts: 6393
Joined: Mon Aug 30, 2010 8:41 am
Contact: Website

Re: Log axis Support - A Solution

See: http://highslide.com/forum/viewtopic.php?f=9&t=8383 however I'm not sure if it'll be possible to have longer tick marks for these scales.
Slawek Kolodziej
Highcharts support team

Return to “Highcharts Usage”