0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-24 00:47:50 +01:00

check data exists in update code

This commit is contained in:
kunal 2021-04-02 07:44:48 -07:00
parent 8e908e6fbb
commit ad55e78f78

View File

@ -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(() => {