浏览代码

Fix: React Graph & Show message on no data (#16278)

Ryan McKinley 6 年之前
父节点
当前提交
236074ea47
共有 1 个文件被更改,包括 33 次插入23 次删除
  1. 33 23
      public/app/plugins/panel/graph2/GraphPanel.tsx

+ 33 - 23
public/app/plugins/panel/graph2/GraphPanel.tsx

@@ -14,36 +14,46 @@ export class GraphPanel extends PureComponent<Props> {
     const { showLines, showBars, showPoints } = this.props.options;
 
     const graphs: GraphSeriesXY[] = [];
-    for (const series of data) {
-      const timeColumn = getFirstTimeField(series);
-      if (timeColumn < 0) {
-        continue;
-      }
+    if (data) {
+      for (const series of data) {
+        const timeColumn = getFirstTimeField(series);
+        if (timeColumn < 0) {
+          continue;
+        }
+
+        for (let i = 0; i < series.fields.length; i++) {
+          const field = series.fields[i];
 
-      for (let i = 0; i < series.fields.length; i++) {
-        const field = series.fields[i];
-
-        // Show all numeric columns
-        if (field.type === FieldType.number) {
-          // Use external calculator just to make sure it works :)
-          const points = getFlotPairs({
-            series,
-            xIndex: timeColumn,
-            yIndex: i,
-            nullValueMode: NullValueMode.Null,
-          });
-
-          if (points.length > 0) {
-            graphs.push({
-              label: field.name,
-              data: points,
-              color: colors[graphs.length % colors.length],
+          // Show all numeric columns
+          if (field.type === FieldType.number) {
+            // Use external calculator just to make sure it works :)
+            const points = getFlotPairs({
+              series,
+              xIndex: timeColumn,
+              yIndex: i,
+              nullValueMode: NullValueMode.Null,
             });
+
+            if (points.length > 0) {
+              graphs.push({
+                label: field.name,
+                data: points,
+                color: colors[graphs.length % colors.length],
+              });
+            }
           }
         }
       }
     }
 
+    if (graphs.length < 1) {
+      return (
+        <div className="panel-empty">
+          <p>No data found in response</p>
+        </div>
+      );
+    }
+
     return (
       <Graph
         series={graphs}