如何从工具提示中删除方形标签并将其信息放在一行?

时间:2017-05-04 22:14:51

标签: chart.js

如何从工具提示中删除此方块?

enter image description here

我更愿意,如果我能设法让它像这样:2月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
            }
        }
    });

3 个答案:

答案 0 :(得分:25)

你去:

  

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

代码:

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;
        }
      }
    }
  }
});

答案 1 :(得分:10)

options对象

中添加此内容
tooltips: {
  displayColors: false
}

答案 2 :(得分:0)

tooltips: {
      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;

        }
      }
    }