From 391065cf0eaea3625d072a98f08b6c73b883f9e9 Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Mon, 7 Oct 2024 12:42:33 +0100 Subject: [PATCH] fix: reading from undefined (#25418) Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- .../scenes/insights/views/LineGraph/LineGraph.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/frontend/src/scenes/insights/views/LineGraph/LineGraph.tsx b/frontend/src/scenes/insights/views/LineGraph/LineGraph.tsx index e7ce47b10176e..fab835e6c5cff 100644 --- a/frontend/src/scenes/insights/views/LineGraph/LineGraph.tsx +++ b/frontend/src/scenes/insights/views/LineGraph/LineGraph.tsx @@ -455,21 +455,28 @@ export function LineGraph_({ datalabels: { color: 'white', anchor: (context) => { - const datum = context.dataset.data[context.dataIndex] + // the type here doesn't allow for undefined, but we see errors where things are undefined + const datum = context.dataset?.data[context.dataIndex] return typeof datum !== 'number' ? 'end' : datum > 0 ? 'end' : 'start' }, backgroundColor: (context) => { - return (context.dataset.borderColor as string) || 'black' + // the type here doesn't allow for undefined, but we see errors where things are undefined + return (context.dataset?.borderColor as string) || 'black' }, display: (context) => { - const datum = context.dataset.data[context.dataIndex] + // the type here doesn't allow for undefined, but we see errors where things are undefined + const datum = context.dataset?.data[context.dataIndex] if (showValuesOnSeries && inSurveyView) { return true } return showValuesOnSeries === true && typeof datum === 'number' && datum !== 0 ? 'auto' : false }, formatter: (value: number, context) => { - const data = context.chart.data as ExtendedChartData + // the type here doesn't allow for undefined, but we see errors where things are undefined + const data = context.chart?.data as ExtendedChartData + if (!data) { + return '' + } const { datasetIndex, dataIndex } = context const percentageValue = data.calculatedData?.[datasetIndex][dataIndex] return formatPercentStackAxisValue(trendsFilter, percentageValue || value, isPercentStackView)