首页 > 解决方案 > chart.js 中的自定义点名称

问题描述

有谁知道如何将自定义名称或工具提示添加到 charts.js 的折线图中的点?只有一个选项可以提供标签(显然是 X)和数据 - 这是 Y....问题是我有另一个数据集 - 它不能与第一个相关联 - 它实际上不是数字......而是字母...但我希望它放在同一个图表上....最好作为点上方的自定义文本 - 但任何其他选项也很好:) 我的代码:hist_fmp_score- 是我想要的标签与 hist_tr_ranks 大小相同的数组

var ctx = document.getElementById('myChart').getContext('2d');
const labels = hist_dates;
const data = {
  labels: labels,
  datasets: [{
    label: 'Ratings',
    data: hist_tr_ranks,
    fill: false,
    borderColor: 'rgb(75, 192, 192)',
    tension: 0.1
  },
  {
    label: 'Score as Letter',
    data: hist_fmp_score,
    fill: false,
    borderColor: 'rgb(255, 99, 132)',
    tension: 0.1
  }]
};
const config = {
  type: 'line',
  data,
  options: {}
};

  var myChart = new Chart(
    document.getElementById('myChart'),
    config
  );

标签: chart.js

解决方案


推荐阅读