Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

tooltip.x position error on line chart

Open sstraus opened this issue 11 years ago • 7 comments

Using the customTooltips on line chart, the tooltip.x position is incorrect after the half of the chart. The behavour is visible also in the line-customTooltips.html example.

sstraus avatar Mar 06 '15 08:03 sstraus

Looking at the standard tooltip behaviour I found that the position change is related to the tooltip position. After the half of the chart it moves on the other side of the dot. Like in the pie chart with the above/below value of yAlign. But there is no xAlign in the tooltip object and I can't find a way to mimic it. Any suggestion?

sstraus avatar Mar 06 '15 08:03 sstraus

I experience the same issue. It might have something to do with responsiveness? With Chart.defaults.global.responsive = true; I notice a slight offset when hovering on the right side of the chart.

BabyDino avatar Apr 08 '15 08:04 BabyDino

+1, same issue, responsive is not the problem... Any idea please ?

pierre-b avatar Apr 17 '15 12:04 pierre-b

Experiencing this too, I have 4 tooltips and 3 and 4 are in the wrong x Position

beardyco avatar Jun 02 '15 12:06 beardyco

+1 for wrong tooltip.x position and tooltip.width when hovering second half of the chart

ModuLIZER avatar Jun 03 '15 18:06 ModuLIZER

The issue seems to come from that bit of code:

            //Decide whether to align left or right based on position on canvas
            if (this.x > this.chart.width/2){
                this.x -= this.xOffset + this.width;
            } else {
                this.x += this.xOffset;
            }

https://github.com/nnnick/Chart.js/blob/930b16a0af59201dcfcd1594b0e7540db4d04c9f/Chart.js#L1396-L1401

Removing that fixes the wrong tooltip.x problem, with the downside that the tooltip won't switch sides on the second half of the chart.

So it's not so much that the tooltip is positioned "incorrectly", it's just that the position gets offset on purpose. Ideally the x position would be constant across both half, and only the label would switch sides through some other means (separate offset, CSS, etc.).

SachaG avatar Jun 04 '15 00:06 SachaG

Huzzah! The first alpha of Chart.js 2.0 has landed and should fix this issue. Check out the release and try it out! We've got a lot of momentum right now, so please help us test so we can launch 2.0 Gold by the end of the month. https://github.com/nnnick/Chart.js/releases/tag/v2.0-alpha

I'm closing this issue for now, but if you have implementation questions or find bugs, please create a jsfiddle and post the link here and we'll reopen this issue and get it fixed.

derekperkins avatar Jun 04 '15 05:06 derekperkins