Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Charts not rerendering on data changes #665

Open
MariuzM opened this issue Dec 19, 2024 · 1 comment
Open

Charts not rerendering on data changes #665

MariuzM opened this issue Dec 19, 2024 · 1 comment

Comments

@MariuzM
Copy link

MariuzM commented Dec 19, 2024

I pass new itemsObj changed, but charts still not rerendering, only soltuion is to key={JSON.stringify(itemsObj)} but this wont be ideal because right now big lag but if chart gets bigger even more.

How to trigger Charts to rerender when prop has changed?

import { Label } from '@/components/Inputs/components/Label'
import { Box } from '@mui/material'
import Chart from 'react-apexcharts'

import type { GraphData } from '../Graph'
import type { ChartTypesT } from '../graph.data'

export const GraphPreview = ({
  itemsObj,
  type,
  isViewMode = false,
}: {
  itemsObj?: GraphData['content']['itemsObj']
  type?: ChartTypesT
  isViewMode?: boolean
}) => {
  if (!itemsObj) return null
  return (
    <Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
      {!isViewMode && <Label id="graph-preview" label="Graph Preview" />}
      <Chart
        key={JSON.stringify(itemsObj)}
        options={{
          ...itemsObj.options,
          chart: {
            id: 'graph-preview',
            animations: { enabled: false },
            toolbar: { show: false },
          },
        }}
        series={itemsObj.series}
        type={type}
        width="500"
      />
    </Box>
  )
}
@ZahidChandio
Copy link

Can you try using another prop for chart re-render? Say "[chartUpdated, setChartUpdated]" and make it setChartUpdated(prev =>!prev) on every update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants