diff --git a/export-csv.js b/export-csv.js index 7897b4c..c103c8b 100644 --- a/export-csv.js +++ b/export-csv.js @@ -24,6 +24,7 @@ rowArr = [], dataRows, names = [], + serieses = this.series.slice(), i, x, @@ -31,8 +32,11 @@ dateFormat = options.dateFormat || '%Y-%m-%d %H:%M:%S'; // Loop the series and index values - i = 0; - each(this.series, function (series) { + i = 0; + serieses.sort(function (a,b) { + return a.options.legendIndex - b.options.legendIndex + }); + each(serieses, function (series) { if (series.options.includeInCSVExport !== false) { names.push(series.name); each(series.points, function (point) { @@ -60,7 +64,7 @@ } // Sort it by X values rowArr.sort(function (a, b) { - return a.x - b.x; + return a.x - b.x; }); // Add header row