Chart.js 不需要 canvas 调整大小

Chart.js unwanted canvas resizing

我正在使用严格定义的宽度和高度将图表绘制到内存中 canvas,然后使用 toDataUrl() 将此 canvas 转换为 base 64。一切正常,直到我在高密度屏幕(全高清笔记本)上使用我的代码,其中 Windows' Display, Scale and Layout > Change the size of text, apps, and other items 选项为 125%,使用此配置,Chart.js 会自动将我的 canvas 调整为原始大小的 125%。

这是一个错误还是我可以禁用的功能?

大概您需要的选项是devicePixelRatio,它将:

Override the window's default devicePixelRatio.

我没有测试过,文档也不是 100% 清楚,但我假设它位于 options 对象的根目录中:

options: {
  devicePixelRatio: 1
}