diff --git a/public/app/plugins/panel/graph/graph.ts b/public/app/plugins/panel/graph/graph.ts index 0556207d08e..82bad53164c 100755 --- a/public/app/plugins/panel/graph/graph.ts +++ b/public/app/plugins/panel/graph/graph.ts @@ -375,20 +375,8 @@ function graphDirective($rootScope, timeSrv, popoverSrv, contextSrv) { var sortOrder = panel.legend.sortDesc; var haveSortBy = sortBy !== null || sortBy !== undefined; var haveSortOrder = sortOrder !== null || sortOrder !== undefined; - - if (panel.stack && haveSortBy && haveSortOrder) { - var desc = desc = panel.legend.sortDesc === true ? -1 : 1; - series.sort((x, y) => { - if (x.stats[sortBy] > y.stats[sortBy]) { - return 1 * desc; - } - if (x.stats[sortBy] < y.stats[sortBy]) { - return -1 * desc; - } - - return 0; - }); - } + var shouldSortBy = panel.stack && haveSortBy && haveSortOrder; + var sortDesc = panel.legend.sortDesc === true ? -1 : 1; series.sort((x, y) => { if (x.zindex > y.zindex) { @@ -399,6 +387,15 @@ function graphDirective($rootScope, timeSrv, popoverSrv, contextSrv) { return -1; } + if (shouldSortBy) { + if (x.stats[sortBy] > y.stats[sortBy]) { + return 1 * sortDesc; + } + if (x.stats[sortBy] < y.stats[sortBy]) { + return -1 * sortDesc; + } + } + return 0; });