JavaScript - Chart.js tooltip shows wrong x-axis value

前端 未结 3 1117
滥情空心
滥情空心 2021-01-20 05:16

I have a chart with two different datasets, but sometimes they have the same x, y coordinates. But when I hover a shared point, it sometimes shows the wrong date. T

3条回答
  •  再見小時候
    2021-01-20 06:12

    I solved my problem by using tooltip callback like this:

    options: {
        tooltips: {
            callbacks: {
                title: function(tooltipItems, data) {
                    return data.datasets[tooltipItems[0].datasetIndex].data[tooltipItems[0].index].x;
                }
            }
        }
    }
    

    Now my tooltips getting their title directly from the corresponding dataset.

    Chartjs Version : 2.9.3

提交回复
热议问题