如何在chart.js2中绘制不带标签的垂直线

时间:2019-04-22 12:48:40

标签: javascript canvas charts chart.js2

我使用chart.js 2.8chartjs-plugin-annotation.js

我有一个条形图。

我的标签是:[1.0 - 2.8], [2.8 - 4.6], [6.4 - 8.2], [8.2 - 10.0]

var ctx = document.getElementById("myChart").getContext("2d");
new Chart(ctx, {
  type: "bar",
  data: {
    labels: labels,
    datasets: [{
      data: datas
    }]
  },
  options: {
    annotation: {
      annotations: [{
        type: "line",
        mode: "vertical",
        scaleID: "x-axis-0",
        value: "2.8 - 4.6", //value must be equal a label :(
        borderColor: "red",
        label: {
          content: "TODAY",
          enabled: true,
          position: "top"
        }
      }]
    }
  }
});

我希望垂直线精确地在 2.4 点上绘制。但是垂直线只能在标签值处绘制。我该如何解决?

0 个答案:

没有答案