[Chartjs]-How to remove background color and color example from tooltip in Chart.js?

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>

Leave a comment