Remove the label and show only value in tooltips of a bar chart - Javascript Chart.js

Javascript examples for Chart.js:Bar Chart

Description

Remove the label and show only value in tooltips of a bar chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.bundle.min.js"></script> 
      <script type="text/javascript">
    window.onload=function(){//  ww w .  j a  va  2 s  . c  om
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
  type: 'bar',
  data: {
     labels: [
      "Men",
      "Women",
      "Unknown"
    ],
    datasets: [
       {
         label: 'Sweden',
        data: [60, 40, 20],
        backgroundColor: [
          'rgba(158, 216, 202, 0.75)',
          'rgba(255, 150, 162, 0.75)',
          'rgba(160, 160, 160, 0.75)'
        ]
      },
      {
         label: 'Netherlands',
        data: [40, 70, 10],
        backgroundColor: [
          'rgba(158, 216, 202, 0.5)',
          'rgba(255, 150, 162, 0.5)',
          'rgba(160, 160, 160, 0.5)'
        ]
      },
       {
        data: [33, 33, 34],
        backgroundColor: [
          'rgba(158, 216, 202, 0.25)',
          'rgba(255, 150, 162, 0.25)',
          'rgba(160, 160, 160, 0.25)'
        ]
      }
    ]
  },
  options: {
    tooltips: {
      callbacks: {
         title: function(tooltipItems, data) {
          return '';
        },
        label: function(tooltipItem, data) {
          var datasetLabel = '';
          var label = data.labels[tooltipItem.index];
          return data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
        }
      }
    }
  }
});
    }

      </script> 
   </head> 
   <body> 
      <canvas id="myChart" width="400" height="200"></canvas>  
   </body>
</html>

Related Tutorials