'How to display small numbers in chart js tooltip?

I am working with chart.js and I have data than is very small like this (0.00000023120098, 0.00000887272934, 0.00000343234). The problem is that, the tooltip only display 0 when I hover on the chart. I tried finding solutions but couldn't find any.



Solution 1:[1]

You will need to override the default label callback so it doesnt do any formatting:

var options = {
  type: 'line',
  data: {
    labels: ["Red", "Blue", "Yellow"],
    datasets: [{
      label: '# of Votes',
      data: [0.00000023120098, 0.00000887272934, 0.00000343234],
      borderColor: 'pink'
    }]
  },
  options: {
    plugins: {
      tooltip: {
        callbacks: {
          label: (ctx) => (`${ctx.dataset.label}: ${ctx.raw}`)
        }
      }
    }
  }
}

var 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.1/chart.js"></script>
</body>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 LeeLenalee