From 4bd79e5454498df18db5446fa5b8d05a1b8fad16 Mon Sep 17 00:00:00 2001 From: Danny Ferguson Date: Fri, 4 Sep 2015 16:15:08 -0500 Subject: [PATCH] Improve bubble and scatter csv The layout for the csv file is now Series Name, X, Y, (Z). Then I use the X and Y axis labels as headers. There's no Z axis label for bubble charts, so I just use 'Bubble Size' as the header. --- export-csv.js | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/export-csv.js b/export-csv.js index 885e02f..6f34853 100644 --- a/export-csv.js +++ b/export-csv.js @@ -34,9 +34,13 @@ i, x, - // Options + + // Options dateFormat = options.dateFormat || '%Y-%m-%d %H:%M:%S'; + if (this.options.chart.type == 'bubble' || this.options.chart.type == 'scatter') { + return this.getBubbleDataRows() + } // Loop the series and index values i = 0; each(this.series, function (series) { @@ -106,6 +110,44 @@ return dataRows; }; + /** + * Get the data rows from bubble and scatter charts + */ + Highcharts.Chart.prototype.getBubbleDataRows = function () { + var dataRows = []; + var bubble = false; + + if (this.options.chart.type == 'bubble') { + bubble = true; + } + + // Headers + var headers = [ + 'Series', + this.options.xAxis[0].title.text, + this.options.yAxis[0].title.text, + ]; + + if (bubble) { + headers.push('Bubble Size') + } + + dataRows.push(headers); + + // Row: Series, X, Y, (Z) + each(this.series, function (series) { + each(series.points, function (point) { + var row = [series.name, point.x, point.y]; + if (bubble) { + row.push(point.z); + } + dataRows.push(row); + }); + }); + + return dataRows; + }; + /** * Get a CSV string */ @@ -247,7 +289,7 @@ '' + this.getTable(true) + '', - base64 = function (s) { + base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))); // #50 }; getContent(