Accepted answer

a very nice question !!!

it is more of a math/geometry issue than a programming/highchart issue. but hey there is an entire subject on this jugglery. computer graphics !!

if i got your question right (i hope i did, else spent an hour solving a non-existent problem, and another drafting an understandable answer).

  • you always want valuex1(90) to align with valudy1(60) and valuex2(140) to align with valuey2(90). x and y are plotted on different y-axis.

here is the solution. all we need to do is align the min's and max's of the two axes correctly for the required points to also align correctly by themselves.

here is how we do that.

  • accept the min & max that is calculated by highcharts as it is for one of the axes and calculate the min & max of the other axis based on the following. (which axis to accept can be tricky, will leave that to be out of scope for this question or as home work =] ). lets go ahead with accepting the 1st axis' values from highchart and calculate values for second ourselves.

  • how to calculate min2/max2 based on min1/max1?

    we use something known as two-point form of solving linear equations

    y - y1 = (y2-y1)/(x2-x1)*(x-x1)

    here x1=90,y1=60,x2=140,y2=90. put a value of x to get corresponding value of y. put min1 to get min2, put max1 to get max2.


var ticksx = {
    t1: 90,
    t2: 140
var ticksy = {
    t1: 60,
    t2: 90

function findy(x) {
    return ticksy.t1 + (x - ticksx.t1) * (ticksy.t2 - ticksy.t1) / (ticksx.t2 - ticksx.t1);

adjust min/max of series2 based on calculated (by highcharts) min/max of series1 on chart load

var chart = new highcharts.chart({...}, function() {
  var minx = this.yaxis[0].getextremes().min;
  var maxx = this.yaxis[0].getextremes().max;
  this.yaxis[1].setextremes(findy(minx), findy(maxx));

aligning ticks in multiple axes | highchart & highstock @ jsfiddle

you will need to fiddle around with the ticks settings and gridlines. will leave that out of scope here as they make up more for a different question

update: code to readjust the ticks based on new extremes

//adjusting ticks
var ticks = 5;
var intervalx = (maxx - minx) / (ticks - 1);
var intervaly = (maxy - miny) / (ticks - 1);
var xticks = [],
    yticks = [];
for (var i = 0; i < ticks; i++) {
    xticks.push(minx + i * intervalx);
    yticks.push(miny + i * intervaly);

chart.yaxis[0].options.tickpositions = xticks;
chart.yaxis[1].options.tickpositions = yticks;


Related Query

More Query from same tag