Reputation: 93
I'm trying to implement a simple ApexChart on a React/Typescript project, however, I'm stuck on the following type error:
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'.
I did install both react-apexcharts
and apexcharts
, as usual.
Here's the script of my chart:
TasksChart.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;
Any thoughts on how to fix this issue? Thanks!
Upvotes: 7
Views: 19961
Reputation: 309
install dependencies with yarn or npm
yarn add apexcharts react-apexcharts
import them
import ReactApexChart from "react-apexcharts";
import { ApexOptions } from "apexcharts";
define type of options
const options: ApexOptions = {
chart: {
height: 350,
type: 'line',
zoom: {
enabled: true
}
},
};
<ReactApexChart
options={options}
series={series}
type="line"
height={350}
/>
that's it =D
Upvotes: 18
Reputation: 510
Looks like you've already set the type
property as the <ReactApexChart />
prop.
Try to remove the type
from the chart
in options
and the error is gone:
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}
/>
);
};
Upvotes: 2