mirror of
https://github.com/grafana/grafana.git
synced 2025-01-27 00:37:04 -06:00
Merge branch 'master' of https://github.com/plopp/grafana into plopp-master
This commit is contained in:
commit
d8929b1d3e
@ -14,6 +14,41 @@ export function exportSeriesListToCsv(seriesList) {
|
||||
saveSaveBlob(text, 'grafana_data_export.csv');
|
||||
};
|
||||
|
||||
export function exportSeriesListToCsvColumns(seriesList) {
|
||||
var text = 'Time;';
|
||||
// add header
|
||||
_.each(seriesList, function(series) {
|
||||
text += series.alias + ';';
|
||||
});
|
||||
text = text.substring(0,text.length-1);
|
||||
text += '\n';
|
||||
|
||||
// process data
|
||||
var dataArr = [[]];
|
||||
var sIndex = 1;
|
||||
_.each(seriesList, function(series) {
|
||||
var cIndex = 0;
|
||||
dataArr.push([]);
|
||||
_.each(series.datapoints, function(dp) {
|
||||
dataArr[0][cIndex] = new Date(dp[1]).toISOString();
|
||||
dataArr[sIndex][cIndex] = dp[0];
|
||||
cIndex++;
|
||||
});
|
||||
sIndex++;
|
||||
});
|
||||
|
||||
// make text
|
||||
for (var i = 0; i < dataArr[0].length; i++) {
|
||||
text += dataArr[0][i] + ';';
|
||||
for (var j = 1; j < dataArr.length; j++) {
|
||||
text += dataArr[j][i] + ';';
|
||||
}
|
||||
text = text.substring(0,text.length-1);
|
||||
text += '\n';
|
||||
}
|
||||
saveSaveBlob(text, 'grafana_data_export.csv');
|
||||
};
|
||||
|
||||
export function exportTableDataToCsv(table) {
|
||||
var text = '';
|
||||
// add header
|
||||
|
@ -126,6 +126,7 @@ class GraphCtrl extends MetricsPanelCtrl {
|
||||
getExtendedMenu() {
|
||||
var menu = super.getExtendedMenu();
|
||||
menu.push({text: 'Export CSV', click: 'ctrl.exportCsv()'});
|
||||
menu.push({text: 'Export CSV (series2columns)', click: 'ctrl.exportCsvColumns()'});
|
||||
menu.push({text: 'Toggle legend', click: 'ctrl.toggleLegend()'});
|
||||
return menu;
|
||||
}
|
||||
@ -295,6 +296,10 @@ class GraphCtrl extends MetricsPanelCtrl {
|
||||
exportCsv() {
|
||||
fileExport.exportSeriesListToCsv(this.seriesList);
|
||||
}
|
||||
|
||||
exportCsvColumns() {
|
||||
fileExport.exportSeriesListToCsvColumns(this.seriesList);
|
||||
}
|
||||
}
|
||||
|
||||
export {GraphCtrl, GraphCtrl as PanelCtrl}
|
||||
|
Loading…
Reference in New Issue
Block a user