diff --git a/components/home/ChartBox/Chart.tsx b/components/home/ChartBox/Chart.tsx index 853e837..ce8835c 100644 --- a/components/home/ChartBox/Chart.tsx +++ b/components/home/ChartBox/Chart.tsx @@ -34,7 +34,7 @@ const Chart = (props: ChartProps) => { const currentPeriodKey = `Current ${currentFilter ? currentFilter.name : ''}`; const prevPeriodKey = `Prev ${currentFilter ? currentFilter.name : ''}`; // Update the date property of each item in prevWeek with the corresponding item from deepCopyCurrentWeek - if (prevPeriod && currentPeriod) + if (prevPeriod && prevPeriod.length > 0 && currentPeriod) prevPeriod.forEach((item, index) => { prevPeriod[index].date = currentPeriod[index]?.date; }); @@ -98,13 +98,15 @@ const Chart = (props: ChartProps) => { {days !== 90 && currentPeriod && prevPeriod && ( <> {/* previous chart only for week and month */} - d.date} - yAccessor={(d) => d.count} - /> + {prevPeriod.length > 0 && ( + d.date} + yAccessor={(d) => d.count} + /> + )} {/* current chart only for week and month */} { {currentPeriod && prevPeriod ? (
-
- - Current: - - {AmountConverter( - tooltipData.datumByKey[currentPeriodKey].datum.count, - )} - -
-
- - Previous: - - {AmountConverter( - tooltipData.datumByKey[prevPeriodKey].datum.count, - )} - -
+ {currentPeriod && ( +
+ + Current: + + {AmountConverter( + tooltipData.datumByKey[currentPeriodKey].datum + .count, + )} + +
+ )} + {prevPeriod.length > 0 && ( +
+ + Previous: + + {AmountConverter( + tooltipData.datumByKey[prevPeriodKey].datum.count, + )} + +
+ )}
) : (