Home>

I want to customize the tooltip position in a bar graph using Chart.js.
Currently it is displayed at the top of the bar in the graph.

https://tr.you84815.space/chartjs/configuration/tooltip.html
I tried the contents of Demo 1 on the above page, but in the first placeChart.Tooltip.positionersis said to be undefined, and an error occurs. I'm in trouble because I don't know what to do next. Thanks for your answer.

  • Answer # 1

    var chart = new Chart (ctx, {
        type: 'line',
        data: data,
        options: {
            tooltips: {
                callbacks: {
                    label: function (tooltipItem, data) {
                        var label = data.datasets [tooltipItem.datasetIndex] .label || '';
                        if (label) {
                            label + = ':';
                        }
                        label + = Math.round (tooltipItem.yLabel * 100)/100;
                        return label;
                    }
                }
            }
        }
    });
      


      https://www.chartjs.org/docs/latest/configuration/tooltip.html?h=html#external-custom-tooltips

  • Answer # 2

    I updated Chart.js and it worked.