Skip to content
This repository was archived by the owner on May 29, 2018. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions export-csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,23 +187,23 @@
var csv = '',
rows = this.getDataRows(),
options = (this.options.exporting || {}).csv || {},
dataFormatter = options.dataFormatter || function (val) {
return Highcharts.numberFormat(val, -1, useLocalDecimalPoint ? (1.1).toLocaleString()[1] : '.', '');
},
itemDelimiter = options.itemDelimiter || ',', // use ';' for direct import to Excel
lineDelimiter = options.lineDelimiter || '\n'; // '\n' isn't working with the js csv data extraction

// Transform the rows to CSV
each(rows, function (row, i) {
var val = '',
j = row.length,
n = useLocalDecimalPoint ? (1.1).toLocaleString()[1] : '.';
j = row.length;
while (j--) {
val = row[j];
if (typeof val === "string") {
val = '"' + val + '"';
}
if (typeof val === 'number') {
if (n === ',') {
val = val.toString().replace(".", ",");
}
val = dataFormatter(val);
}
row[j] = val;
}
Expand All @@ -223,24 +223,24 @@
*/
Highcharts.Chart.prototype.getTable = function (useLocalDecimalPoint) {
var html = '<table><thead>',
rows = this.getDataRows();
rows = this.getDataRows(),
options = (this.options.exporting || {}).csv || {},
dataFormatter = options.dataFormatter || function (val) {
return Highcharts.numberFormat(val, -1, useLocalDecimalPoint ? (1.1).toLocaleString()[1] : '.', '');
};

// Transform the rows to HTML
each(rows, function (row, i) {
var tag = i ? 'td' : 'th',
val,
j,
n = useLocalDecimalPoint ? (1.1).toLocaleString()[1] : '.';
j;

html += '<tr>';
for (j = 0; j < row.length; j = j + 1) {
val = row[j];
// Add the cell
if (typeof val === 'number') {
val = val.toString();
if (n === ',') {
val = val.replace('.', n);
}
val = dataFormatter(val);
html += '<' + tag + ' class="number">' + val + '</' + tag + '>';

} else {
Expand Down