From ad55e78f786166d1490a24291adad92433b68014 Mon Sep 17 00:00:00 2001 From: kunal Date: Fri, 2 Apr 2021 07:44:48 -0700 Subject: [PATCH] check data exists in update code --- frontend/src/scenes/trends/viz/ActionsPie.tsx | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/frontend/src/scenes/trends/viz/ActionsPie.tsx b/frontend/src/scenes/trends/viz/ActionsPie.tsx index 6a6ca88c073..3f4640ab26b 100644 --- a/frontend/src/scenes/trends/viz/ActionsPie.tsx +++ b/frontend/src/scenes/trends/viz/ActionsPie.tsx @@ -23,23 +23,26 @@ export function ActionsPie({ function updateData(): void { const _data = results as TrendResultWithAggregate[] - _data.sort((a, b) => b.aggregated_value - a.aggregated_value) - const colorList = getChartColors(color) + if (_data) { + _data.sort((a, b) => b.aggregated_value - a.aggregated_value) - setData([ - { - labels: _data.map((item) => item.label), - data: _data.map((item) => item.aggregated_value), - backgroundColor: colorList, - hoverBackgroundColor: colorList, - hoverBorderColor: colorList, - borderColor: colorList, - hoverBorderWidth: 10, - borderWidth: 1, - }, - ]) - setTotal(_data.reduce((prev, item) => prev + item.aggregated_value, 0)) + const colorList = getChartColors(color) + + setData([ + { + labels: _data.map((item) => item.label), + data: _data.map((item) => item.aggregated_value), + backgroundColor: colorList, + hoverBackgroundColor: colorList, + hoverBorderColor: colorList, + borderColor: colorList, + hoverBorderWidth: 10, + borderWidth: 1, + }, + ]) + setTotal(_data.reduce((prev, item) => prev + item.aggregated_value, 0)) + } } useEffect(() => {