[英]React Apexcharts not working with Typescript
我正在尝试在 React/Typescript 项目上实现一个简单的 ApexChart,但是,我遇到了以下类型错误:
No overload matches this call. Overload 1 of 2, '(props: Props | Readonly): ReactApexChart', gave the following error. Type '{ chart: { height: ApexOptions; type: ApexOptions; zoom: { enabled: ApexOptions; }; }; }' is not assignable to type 'ApexOptions'. The types of 'chart.height' are incompatible between these types. Type 'ApexOptions' is not assignable to type 'string | number | undefined'. Type 'ApexOptions' is not assignable to type 'number'. Overload 2 of 2, '(props: Props, context: any): ReactApexChart', gave the following error. Type '{ chart: { height: ApexOptions; type: ApexOptions; zoom: { enabled: ApexOptions; }; }; }' is not assignable to type 'ApexOptions'.
我像往常一样安装了react-apexcharts
和apexcharts
。 这是我图表的脚本:
任务图表.tsx
import ReactApexChart from 'react-apexcharts';
const TasksChart: React.FC<Props> = ({
tasks,
}) => {
const options = {
chart: {
height: 350,
type: 'line',
zoom: {
enabled: true
}
},
};
series = [{
name: 'All Tasks',
data: [31, 40, 28, 51, 42, 109, 100]
}, {
name: 'My Tasks',
data: [11, 32, 45, 32, 34, 52, 41]
}]
return (
<>
<ReactApexChart options={options} series={series} type="line" height={350} />
</>
);
};
export default TasksChart;
关于如何解决此问题的任何想法? 谢谢!
看起来您已经将type
属性设置为<ReactApexChart />
属性。
尝试从options
中的chart
中删除type
,错误消失了:
const TasksChart: React.FC<Props> = ({ tasks }) => {
const options = {
chart: {
height: 350,
zoom: {
enabled: true
}
}
};
const series = [
{
name: "All Tasks",
data: [31, 40, 28, 51, 42, 109, 100]
},
{
name: "My Tasks",
data: [11, 32, 45, 32, 34, 52, 41]
}
];
return (
<ReactApexChart
type="line"
options={options}
series={series}
height={350}
/>
);
};
使用 yarn 或 npm 安装依赖项
yarn add apexcharts react-apexcharts
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.