Chart.js - “options.legend.position”的类型在这些类型之间不兼容

Ped*_*vas 3 charts graph legend typescript

我想将图例放在图形下面(这很简单),但是代码根本不起作用,给我以下错误:

The types of 'options.legend.position' are incompatible between these types.
Type 'string' is not assignable to type '"bottom" | "left" | "right" | "top" | "chartArea" | undefined'.
Run Code Online (Sandbox Code Playgroud)

更糟糕的是,我在 CodeSandBox 中得到了相同的代码,没有任何区别,并且运行良好......这是它的链接:https://codesandbox.io/s/spring-hill-3nme9 ?file=/src/components /Scatter.tsx

有什么帮助吗?谢谢!

小智 6

将位置设置为 cons 对我有用

options: {
            responsive: true,
            maintainAspectRatio: false,
            legend: {
                display: true,
                position: "bottom" as const, // <----
                labels: {
                    fontColor: "#000080"
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)