trend: choose trend crash (#95451)

* fix bug

* optimise warning return
This commit is contained in:
jackyin
2024-11-07 21:48:50 +08:00
committed by GitHub
parent a415c0b831
commit 1e58747a39

View File

@@ -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',