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”作为常量和消除了打字错误。不过,我不确定是否还有其他问题。
优秀答案推荐
我是一名优秀的程序员,十分优秀!