I have tried and failed to integrate two different chart libraries into Remix, just looking for some help around what I'm doing wrong here. I saw about splitting out the chart code into a separate file with .client and using <ClientOnly> from remix-utils so it's only rendered on the client side.
I'm using react-apexcharts and have a split between two files:
// ~/components/BarChart.client.js
export const BarChart = (input) => {
const options = {
labels: input.labels,
// .......
}
const series = [{ name: 'total', data: input.data }]
return <ReactApexChart type="bar" series={series} options={options} height={364} />
}
// ~/routes/analytics.js
export const loader = async ({ request }) => {
await getUser(request)
const data = {
labels: ['2022-01-01', '2022-02-01', '2022-03-01'],
data: [100, 200, 300],
}
return json({ data })
}
export default function Analytics() {
const { data } = useLoaderData()
return (
<div className="divider-vertical m-2 p-2">
<ClientOnly fallback={<p>Cannot load chart</p>}>
{() => <BarChart input={data} />}
</ClientOnly>
</div>
)
}
I'm getting an error in ApexCharts:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'length')
at t2.value (apexcharts.common.js:6:137588)
at t2.value (apexcharts.common.js:6:141311)
at t2.value (apexcharts.common.js:14:38129)
at t2.create (apexcharts.common.js:6:4483)
at apexcharts.common.js:14:37129
at new Promise (<anonymous>)
at t2.value (apexcharts.common.js:14:21643)
at r.value (react-apexcharts.min.js:1:2762)
at commitLifeCycles (react-dom.development.js:20663:24)
at commitLayoutEffects (react-dom.development.js:23426:7)
It looks like an issue with ApexCharts, but I have verified this works in a plain old Create React App setup, it seems to be only in Remix that it has this issue