【问题标题】:Chart.js - The types of 'options.legend.position' are incompatible between these typesChart.js - 'options.legend.position' 的类型在这些类型之间不兼容
【发布时间】:2020-07-27 05:54:07
【问题描述】:

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

The types of 'options.legend.position' are incompatible between these types.
Type 'string' is not assignable to type '"bottom" | "left" | "right" | "top" | "chartArea" | undefined'.

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

有什么帮助吗?谢谢!

【问题讨论】:

    标签: typescript graph charts legend


    【解决方案1】:

    scatter 图表期望数据作为对象数组传递,每个对象包含 x 和 y 属性。根据您的数据,您可以通过定义type: "line" 并将showLine: false 添加到每个数据集来将图表类型更改为折线图。

    const chartConfig = {
      type: "line",
      data: {
        datasets: [{
          label: "Bar Dataset",
          data: [10, 20, 30, 40],
          showLine: false
        },
        {
          label: "Line Dataset",
          data: [50, 50, 50, 50],
          type: "line",
          showLine: false
        }    
    

    请查看您修改后的Sandbox

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-17
      • 2020-02-10
      • 2021-07-07
      • 2014-09-04
      • 1970-01-01
      • 1970-01-01
      • 2015-10-31
      • 1970-01-01
      相关资源
      最近更新 更多