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

How to remove this square from the tooltip?

enter image description here

I would prefer if I could just create one line: 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
            }
        }
    });
+6
source share
2 answers

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;
        }
      }
    }
  }
});
+12
source

Add this to your optionsobject

tooltips: {
  displayColors: false
}
+1
source

Source: https://habr.com/ru/post/1017006/


All Articles