gpt4 book ai didi

Plotly does not know 'bar' type in react-js with typescript(Plotly不知道带有typescript的react js中的“bar”类型)

转载 作者:bug小助手 更新时间:2023-10-22 18:05:10 29 4
gpt4 key购买 nike



I am trying to run a minimal working example of using a plotly bar char in an React JS project with typescript but I get typescript errors complaining that 'bar' is not a valid option. It is/should be and the example works in a non-typescript React project.

我正在尝试运行一个在React JS项目中使用带typescript的plotly bar char的最小工作示例,但我收到了typescript错误,抱怨“bar”不是一个有效的选项。它是/应该是,并且该示例适用于非typescript React项目。


This is error I get - it complains about some violin data type which does not make sense to me:

这是我得到的错误-它抱怨一些小提琴数据类型对我来说没有意义:


TS2769: No overload matches this call.
Overload 1 of 2, '(props: PlotParams | Readonly<PlotParams>): Plot', gave the following error.
Type '{ x: number[]; y: number[]; type: string; name: string; }[]' is not assignable to type 'Data[]'.
Type '{ x: number[]; y: number[]; type: string; name: string; }' is not assignable to type 'Data'.
Type '{ x: number[]; y: number[]; type: string; name: string; }' is not assignable to type 'Partial<ViolinData>'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"violin"'.
Overload 2 of 2, '(props: PlotParams, context: any): Plot', gave the following error.
Type '{ x: number[]; y: number[]; type: string; name: string; }[]' is not assignable to type 'Data[]'.

This my code piece

这是我的代码


import React from "react";
import Plot from "react-plotly.js";

function App() {
const data = [
{
x: [1, 2, 3],
y: [100, 50, 300],
type: "bar",
name: "Health",
},
];


return (
<div className="App">
<Plot data={data} />
</div>
);
}

export default App;


更多回答

I managed to remove the typescript error by using type: "bar" as const and <Plot data={data} layout={{}} />. Not sure if there are any other problems, though.

我设法通过使用类型:“bar”作为常量和<Plot data={data}layout={{}}/>来消除typescript错误。不过,不确定是否还有其他问题。

优秀答案推荐
更多回答

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com