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

TypeError: Cannot read properties of undefined (reading 'Chart') #345

Open
Strydom opened this issue Apr 22, 2023 · 1 comment
Open

TypeError: Cannot read properties of undefined (reading 'Chart') #345

Strydom opened this issue Apr 22, 2023 · 1 comment

Comments

@Strydom
Copy link

Strydom commented Apr 22, 2023

No type errors, but when rendering this error is thrown.

"react-charts": "3.0.0-beta.54"

import { Chart as GoogleChart } from "react-google-charts";
import { AxisOptions, Chart as ReactChart } from 'react-charts';

...

function TemperatureChartReact({ normals }: { normals: Record<Month, { tmin: number, tmax: number }> }) {
  type Temperature = {
    month: Month,
    temperature: number,
  }

  type Series = {
    label: string,
    data: Temperature[]
  }

  const data = useMemo(() => {
    return Object
      .entries(normals)
      .map(([month, normal]) =>({
        month: Number.parseInt(month) as Month,
        temperature: normal.tmax
      }))
  }, [normals])

  const series: Series[] = [
    {
      label: 'Temperature',
      data
    }
  ]

  const primaryAxis = React.useMemo(
    (): AxisOptions<Temperature> => ({
      getValue: datum => datum.month
    }),
    []
  )

  const secondaryAxes = React.useMemo(
    (): AxisOptions<Temperature>[] => [
      {
        getValue: datum => datum.temperature
      }
    ],
    []
  )

  return (
    <ReactChart
      options={{
        data: series,
        primaryAxis,
        secondaryAxes
      }}
    />
  )
}

Series object

[
  {
    label: 'Temperature',
    data: [
      { month: 1, temperature: 22.46 },
      { month: 2, temperature: 24.56 },
      { month: 3, temperature: 26.67 },
      { month: 4, temperature: 29.56 },
      { month: 5, temperature: 32.25 },
      { month: 6, temperature: 33.48 },
      { month: 7, temperature: 33.14 },
      { month: 8, temperature: 32.59 },
      { month: 9, temperature: 31.46 },
      { month: 10, temperature: 29.36 },
      { month: 11, temperature: 27.36 },
      { month: 12, temperature: 24.04 }
    ]
  }
]

@ori-maci
Copy link

I am facing the same issue, has anyone been able to resolve this?

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