score:2

Accepted answer

you can't use css since its not html styling because its drawn on the canvas.

what you can do is provide a custom positioner for the tooltip to chart.js.
in the sample below you can see how to do it. increading the yoffset variable i declared on top will move the tooltip more above the point and increasing the xoffset variable i declared on top it will move the tooltip more to the right:

const yoffset = 10;
const xoffset = 00;

chart.tooltip.positioners.custom = function(items) {
  const pos = chart.tooltip.positioners.average(items);

  // happens when nothing is found
  if (pos === false) {
    return false;
  }

  const chart = this.chart;

  return {
    x: pos.x + xoffset,
    y: pos.y - yoffset,
    yalign: 'bottom',
  };
}

const options = {
  type: 'line',
  data: {
    labels: ["red", "blue", "yellow", "green", "purple", "orange"],
    datasets: [{
        label: '# of votes',
        data: [12, 19, 3, 5, 2, 3],
        borderwidth: 1
      },
      {
        label: '# of points',
        data: [7, 11, 5, 8, 3, 7],
        borderwidth: 1
      }
    ]
  },
  options: {
    plugins: {
      tooltip: {
        caretpadding: 3,
        caretsize: 0,
        displaycolors: false,
        backgroundcolor: 'rgba(45,132,180,0.8)',
        bodyfontcolor: 'rgb(255,255,255)',
        callbacks: {
          title: () => {
            return
          },
          label: (ttitem) => (`${ttitem.parsed.y} ppm`),
          afterbody: (ttitems) => (ttitems[0].label)
        },
        position: 'custom'
      }
    }
  }
}

const ctx = document.getelementbyid('chartjscontainer').getcontext('2d');
new chart(ctx, options);
<body>
  <canvas id="chartjscontainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/3.7.0/chart.js"></script>
</body>


Related Query

More Query from same tag