diff --git a/public/app/features/transformers/calculateHeatmap/heatmap.test.ts b/public/app/features/transformers/calculateHeatmap/heatmap.test.ts index 256cd576ebe..4155a763d4d 100644 --- a/public/app/features/transformers/calculateHeatmap/heatmap.test.ts +++ b/public/app/features/transformers/calculateHeatmap/heatmap.test.ts @@ -108,4 +108,17 @@ describe('Heatmap transformer', () => { ] `); }); + + it('throws error if no numeric fields are present', async () => { + expect(() => + rowsToCellsHeatmap({ + frame: toDataFrame({ + fields: [ + { name: 'time', type: FieldType.time, values: [1, 2, 3, 4] }, + { name: 'label', type: FieldType.string, values: ['a', 'b', 'c', 'd'] }, + ], + }), + }) + ).toThrowErrorMatchingInlineSnapshot(`"No numeric fields found for heatmap"`); + }); }); diff --git a/public/app/features/transformers/calculateHeatmap/heatmap.ts b/public/app/features/transformers/calculateHeatmap/heatmap.ts index 7968444302d..49a54bb43f1 100644 --- a/public/app/features/transformers/calculateHeatmap/heatmap.ts +++ b/public/app/features/transformers/calculateHeatmap/heatmap.ts @@ -125,6 +125,10 @@ export function rowsToCellsHeatmap(opts: RowsHeatmapOptions): DataFrame { const xValues = xField.values; const yFields = opts.frame.fields.filter((f, idx) => f.type === FieldType.number && idx > 0); + if (yFields.length === 0) { + throw new Error(t('heatmap.error.no-y-fields', 'No numeric fields found for heatmap')); + } + // similar to initBins() below const len = xValues.length * yFields.length; const xs = new Array(len); diff --git a/public/app/plugins/panel/heatmap/HeatmapPanel.tsx b/public/app/plugins/panel/heatmap/HeatmapPanel.tsx index e3546d7fdf2..4d2762a9be3 100644 --- a/public/app/plugins/panel/heatmap/HeatmapPanel.tsx +++ b/public/app/plugins/panel/heatmap/HeatmapPanel.tsx @@ -55,6 +55,7 @@ export const HeatmapPanel = (props: HeatmapPanelProps) => { timeRange, }); } catch (ex) { + console.error(ex); return { warning: `${ex}` }; } }, [data.series, data.annotations, options, palette, theme, replaceVariables, timeRange]); diff --git a/public/locales/en-US/grafana.json b/public/locales/en-US/grafana.json index 6e4ecb98f4d..f690c04b70a 100644 --- a/public/locales/en-US/grafana.json +++ b/public/locales/en-US/grafana.json @@ -9153,6 +9153,9 @@ "category-legend": "Legend", "category-tooltip": "Tooltip", "category-y-axis": "Y Axis", + "error": { + "no-y-fields": "No numeric fields found for heatmap" + }, "mode-options": { "label-opacity": "Opacity", "label-scheme": "Scheme"