U
U
uRoot2021-06-04 17:51:09
React
uRoot, 2021-06-04 17:51:09

How can I add HTML to the tooltip in Chart.js?

I need to wrap a part of the text with a div in the tooltip. How can i do this?
60ba3d71c139e860911284.png

I try like this:

const options = {
    tooltips: {
callbacks: {
        label: (tooltipItem: any, data: any) => {
          let label = data.datasets[tooltipItem.datasetIndex].label || '';

          if (label) {
            label += `: $`;
          }

          const span = document.createElement('div');
          span.style.background = 'red'
          span.style.borderColor = "#000";
          span.style.borderWidth = '2px';
          span.style.marginRight = '10px';
          span.style.height = '10px';
          span.style.width = '10px';

          label += tooltipItem.yLabel;

           const el  = span.innerText = label
          
          return el;
        },
      },
    }
}


But in the end, just text without a div is displayed. Do not tell me how to do it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question