Kaynağa Gözat

Graph: added export graph time series data as csv file feature, accessed from panel menu dropdown, #861

Torkel Ödegaard 11 yıl önce
ebeveyn
işleme
640c558446
3 değiştirilmiş dosya ile 17 ekleme ve 0 silme
  1. 1 0
      CHANGELOG.md
  2. 11 0
      src/app/components/kbn.js
  3. 5 0
      src/app/panels/graph/module.js

+ 1 - 0
CHANGELOG.md

@@ -8,6 +8,7 @@
 - [Issue #850](https://github.com/grafana/grafana/issues/850). Graph: Shared tooltip that shows multiple series & crosshair line, thx @toni-moreno
 - [Issue #940](https://github.com/grafana/grafana/issues/940). Graph: New series style override option "Fill below to", useful to visualize max & min as a shadow for the mean
 - [Issue #1030](https://github.com/grafana/grafana/issues/1030). Graph: Legend table display/look changed, now includes column headers for min/max/avg, and full width (unless on right side)
+- [Issue #861](https://github.com/grafana/grafana/issues/861). Graph: Export graph time series data as csv file
 
 **New Panels**
 - [Issue #951](https://github.com/grafana/grafana/issues/951). SingleStat: New singlestat panel

+ 11 - 0
src/app/components/kbn.js

@@ -459,6 +459,17 @@ function($, _, moment) {
       .replace(/ +/g,'-');
   };
 
+  kbn.exportSeriesListToCsv = function(seriesList) {
+    var text = 'Series;Time;Value\n';
+    _.each(seriesList, function(series) {
+      _.each(series.datapoints, function(dp) {
+        text += series.alias + ';' + new Date(dp[1]).toISOString() + ';' + dp[0] + '\n';
+      });
+    });
+    var blob = new Blob([text], { type: "text/csv;charset=utf-8" });
+    window.saveAs(blob, 'grafana_data_export.csv');
+  };
+
   kbn.stringToJsRegex = function(str) {
     if (str[0] !== '/') {
       return new RegExp(str);

+ 5 - 0
src/app/panels/graph/module.js

@@ -30,6 +30,7 @@ function (angular, app, $, _, kbn, moment, TimeSeries, PanelMeta) {
     $scope.panelMeta.addEditorTab('Axes & Grid', 'app/panels/graph/axisEditor.html');
     $scope.panelMeta.addEditorTab('Display Styles', 'app/panels/graph/styleEditor.html');
 
+    $scope.panelMeta.addExtendedMenuItem('Export CSV', '', 'exportCsv()');
     $scope.panelMeta.addExtendedMenuItem('Toggle legend', '', 'toggleLegend()');
 
     // Set and populate defaults
@@ -283,6 +284,10 @@ function (angular, app, $, _, kbn, moment, TimeSeries, PanelMeta) {
       $scope.get_data();
     };
 
+    $scope.exportCsv = function() {
+      kbn.exportSeriesListToCsv($scope.seriesList);
+    };
+
     panelSrv.init($scope);
   });