我怎样才能为 x 轴上的点放置一个字符串?

How could I put a string for the points on the x-axis?

我正在使用 ChartJS v.2,我想用一个字符串来标记 arrayX,当鼠标悬停在显示坐标时该字符串会出现。

A​​rrayX 是点(数字)我应该用一些东西来标记。

 data = {
      labels: arrayX,
      datasets: [{
        label: 'ArrayY',
        data: arrayY,
        fill: false,
        borderColor: 'rgb(75, 192, 192)',
        tension: 0.1
      }]
    };

您可以为此使用标题回调:

var options = {
  type: 'line',
  data: {
    labels: ["10", "15", "30", "80", "5000", "999999"],
    datasets: [{
        label: '# of Votes',
        data: [12, 19, 3, 5, 2, 3],
        borderWidth: 1
      },
      {
        label: '# of Points',
        data: [7, 11, 5, 8, 3, 7],
        borderWidth: 1
      }
    ]
  },
  options: {
    tooltips: {
      callbacks: {
        title: (a) => ('Test string: ' + a[0].label)
      }
    }
  }
}

var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
  <canvas id="chartJSContainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script>
</body>

我用这个方法解决了,比较简单

options: {
            tooltips: {
              callbacks: {
                title:function(tooltipItems, data){
                     return 'Y: ' + tooltipItems[0].xLabel;
                } 
              }
            }
          }