From 1e58747a3944619c55df36dd61b0304b879e3509 Mon Sep 17 00:00:00 2001 From: jackyin Date: Thu, 7 Nov 2024 21:48:50 +0800 Subject: [PATCH] trend: choose trend crash (#95451) * fix bug * optimise warning return --- public/app/plugins/panel/trend/TrendPanel.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/public/app/plugins/panel/trend/TrendPanel.tsx b/public/app/plugins/panel/trend/TrendPanel.tsx index 0d7d398ab01..b787f799d92 100644 --- a/public/app/plugins/panel/trend/TrendPanel.tsx +++ b/public/app/plugins/panel/trend/TrendPanel.tsx @@ -29,8 +29,7 @@ export const TrendPanel = ({ const { dataLinkPostProcessor } = usePanelContext(); // Need to fallback to first number field if no xField is set in options otherwise panel crashes 😬 const trendXFieldName = - options.xField ?? data.series[0].fields.find((field) => field.type === FieldType.number)?.name; - + options.xField ?? data.series[0]?.fields.find((field) => field.type === FieldType.number)?.name; const preparePlotFrameTimeless = (frames: DataFrame[], dimFields: XYFieldMatchers, timeRange?: TimeRange | null) => { dimFields = { ...dimFields, @@ -61,7 +60,7 @@ export const TrendPanel = ({ } else { // first number field // Perhaps we can/should support any ordinal rather than an error here - xFieldIdx = frames[0].fields.findIndex((f) => f.type === FieldType.number); + xFieldIdx = frames[0] ? frames[0].fields.findIndex((f) => f.type === FieldType.number) : -1; if (xFieldIdx === -1) { return { warning: 'No numeric fields found for X axis',