2

How to remove background color and color example from tooltip in Chart.js?

I want him to be not just white but transparent and show only this number, not a square with an example of color.

enter image description here

John Doe
  • 3,794
  • 9
  • 40
  • 72

1 Answers1

5

using the tooltips option,

assign a transparent color to --> backgroundColor: 'rgba(0, 0, 0, 0)'

to remove the color square, use --> displayColors: false

options: {
  tooltips: {
    backgroundColor: 'rgba(0, 0, 0, 0)',
    displayColors: false
  }
}

see following working snippet...

$(document).ready(function() {

  var myPieChart = new Chart(document.getElementById('myChart').getContext('2d'),{
    type: 'pie',
    data: {
      datasets: [{
        data: [10, 20, 30],
        backgroundColor: ['rgb(255, 99, 132)','rgb(54, 162, 235)','rgb(255, 205, 86)']
      }],
      labels: [
        'Red',
        'Yellow',
        'Blue'
      ]
    },
    options: {
      tooltips: {
        backgroundColor: 'rgba(0, 0, 0, 0)',
        bodyFontColor: '#000000',
        displayColors: false
      }
    }
  });

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>
<canvas id="myChart"></canvas>
WhiteHat
  • 59,912
  • 7
  • 51
  • 133