apexchart] 'TypeError: Cannot read properties of null (reading 'replace')' 에러해결

짱효·2024년 12월 24일

'TypeError: Cannot read properties of null (reading 'replace')'

해당 에러가 뜨면 무조건 data값에 0값이나 null 이 있는지 확인하고
해당 값을 필터링 한다음 series에 넣어주면 해결된다.

  let filteredData
    if (data) {
        filteredData = data.map(item => ({
            name: item.name,
            data: item.data.filter(
                subItem =>
                    subItem.x !== null &&
                    subItem.x !== undefined &&
                    subItem.y !== null &&
                    subItem.y !== undefined &&
                    subItem.z !== null &&
                    subItem.z !== undefined &&
                    subItem.y !== 0
            ),
        }))
        console.log('data', filteredData)
    } else {
        console.log('data가 존재하지 않습니다.')
    }
    

예를들어)

{x: null , y: 'dddd', z:'dddd'}

이런식으로 값이있으면 무조건 난다.
모든 각 값에 예외처리 해주면 해결된다.

profile
✨🌏확장해 나가는 프론트엔드 개발자입니다✏️

0개의 댓글