0

I want to add a '%' to the hover concatenated to my data. So let's say I have:

const data = {
  maintainAspectRatio: false,
  responsive: false,
  labels: ["a", "b"],
  datasets: [
    {
      data: [50, 50],
      backgroundColor: ['rgba(12, 29, 213, 0.89)', 'rgba(49, 58, 52, 0.89)'],
      hoverBackgroundColor: ['#1f2bae','#242825']

    }
  ]
};

it displays like this:

Doughnut example

Now I just want a % concatenated to the 50. So my question is how do I do this given that I always have the % as data but just as a number without the % ?

Edit: my working solution works like this:

tooltip: {
                    callbacks: {
                      label: function(data ) {
                        var label = data.dataset.label || '';

                        
                        if (data.parsed.y !== null) {
                            label += data.parsed+'%';
                        }
                        return label;
                    }
                    }
                  }
  • I now have a solution that is like this: – TheDarkHunter Oct 24 '21 at 18:07
  • I kind of have a solution now but I need the tooltipItem.index for it, but once i add the tooltipItem parameter to my function my data doesn't work anymore and I get an error that my data is undefined: function(tooltipItem, data) causes this error, function(data) doesn't cause it but I can't get the index of the hovered item – TheDarkHunter Oct 24 '21 at 18:13

0 Answers0