gpt4 book ai didi

Plotly does not know 'bar' type in react-js with typescript(Ploly不知道带有类型脚本的Reaction-js中的‘bar’类型)

转载 作者:bug小助手 更新时间:2023-10-24 17:10:54 26 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.

我正在尝试运行一个最小的工作示例,在带有TypeScrip的Reaction JS项目中使用绘制条形字符,但我收到了打印脚本错误,抱怨‘bar’不是一个有效的选项。它是/应该是的,并且该示例在非类型脚本的Reaction项目中工作。


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.

我设法通过使用type:“bar”作为常量和消除了打字错误。不过,我不确定是否还有其他问题。

优秀答案推荐
更多回答

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