0

我尝试使用 EMI 计算器模块,但在属性“xAxes”上遇到错误,该错误在类型“_DeepPartialObject<{ [key: string]: ScaleOptionsByType; }>' 。

我无法联系 github 中的开发人员。我可以在这个小组寻求建议吗?

https://github.com/eskutti/EMI-Calculator/issues/1

this.barChart = new Chart(this.barCanvas.nativeElement, {
  type: 'bar',
  data: {
    labels: labels,
    datasets: [{
      label: 'Perincipal',
      backgroundColor: "rgba(0, 179, 0,0.5)",
      data: principals
    }, {
      label: 'Interest',
      backgroundColor: "rgba(255, 26, 26, 0.5)",
      data: interests
    }]
  },
  options: {
    title: {
      display: false,
    },
    tooltips: {
      mode: 'index',
      intersect: false
    },
    responsive: true,
    scales: {
      xAxes: [{
        gridLines: {
          display: false
        },
        stacked: true,
      }],
      yAxes: [{
        gridLines: {
          display: false
        }, ticks: {
          // Include a dollar sign in the ticks
          callback: function (value, index, values) {
            let n = value;
            let d = 2;
            let x = ('' + n).length;
            let p = Math.pow;
            d = p(10, d)
            x -= x % 3
            return Math.round(n * d / p(10, x)) / d + " kMGTPE"[x / 3]
            //return this.abbrNum(value, 2);
          }
        },
        stacked: true,
      }]
    }
  }
});
4

1 回答 1

1

从错误看来,您正在运行 chart.js 版本 3,而您的配置是 v2 语法,因此它可能需要 chart.js 版本 2,

尝试运行npm i chart.js@2.9.4以安装最新版本的 v2,它应该可以工作。

于 2021-06-08T18:24:36.110 回答