Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove square label from tooltip and make its information in one line?

Tags:

chart.js

How can I remove this square from tooltip?

enter image description here

I would prefer if I could manage to just have it one line like this: February - 2

var data = {         labels: ['January', 'February', 'March'],         datasets: [         {             data: [1,2,3]         }         ]     };      var myLineChart = new Chart(document.getElementById('chart'), {         type: 'line',         data: data,         options: {             legend: {                 display: false             }         }     }); 
like image 313
Marko Avatar asked May 04 '17 22:05

Marko


2 Answers

Add this in your options object

tooltips: {   displayColors: false } 
like image 182
Seph Cordovano Avatar answered Sep 19 '22 22:09

Seph Cordovano


here you go:

jsfiddle: http://jsfiddle.net/1v9fy5mz/

code:

html

<canvas id="canvas"></canvas>

js:

var ctx = document.getElementById("canvas").getContext("2d");  var data = {   labels: ['January', 'February', 'March'],   datasets: [{     data: [1, 2, 3]   }] };  var myLineChart = new Chart(ctx, {   type: 'line',   data: data,   options: {     showAllTooltips: true,     tooltips: {       custom: function(tooltip) {         if (!tooltip) return;         // disable displaying the color box;         tooltip.displayColors = false;       },       callbacks: {         // use label callback to return the desired label         label: function(tooltipItem, data) {           return tooltipItem.xLabel + " :" + tooltipItem.yLabel;         },         // remove title         title: function(tooltipItem, data) {           return;         }       }     }   } }); 
like image 27
Ahmed Musallam Avatar answered Sep 20 '22 22:09

Ahmed Musallam