var data = [45, 31, 23], // whatever your data is graphHeight = 400, // however many ticks you want to set numberTicksY = 4, // set y scale // (hardcoded domain in this example to min and max of data vals > you should use d3.max real life) y = d3.scale.linear().range(graphHeight, 0]).domain(23, 45), yAxis = d3.svg.axis().scale(y).orient("left").ticks(numberTicksY), // eg returns -> [20, 30, 40, 50] tickArr = y.ticks(numberTicksY), // use last 2 ticks (cld have used first 2 if wanted) with y scale fn to determine positions tickDistance = y(tickArr[tickArr.length - 1]) - y(tickArr[tickArr.length - 2]);
source share