I' ve created tooltips on multi-series line chart following the answer here. If I mouse over the last date as you can see in this picture:
the tooltips are overlapping. What I want is when tooltips are overlapping, move any of them a little higher or lower. I was trying to do this by changing the code below.
var beginning = 0,
end = lines[i].getTotalLength(),
target = null;
//console.log(lines[i])
//console.log(end)
while (true){
target = Math.floor((beginning + end) / 2);
pos = lines[i].getPointAtLength(target);
if ((target === end || target === beginning) && pos.x !== mouse[0]) {
break;
}
console.log(pos)
if (pos.x > mouse[0]) end = target;
else if (pos.x < mouse[0]) beginning = target;
else break; //position found
}
My thought was recalculating the end
. If the substraction of lines[0].getTotalLength()
and lines[1].getTotalLength()
is less than or larger than a value, then update the value of end(eg. end = end + 20).But I didn't get the code work here.
Does anybody know how to do this? Or is there an easier way to avoid tooltips overlapping?