Reputation: 43
I'd like to add a row at the end of the exported CSV file that contains a string with the source citation for the downloaded data.
Is this possible?
Upvotes: 2
Views: 426
Reputation: 20536
You could extend Highcharts and wrap the getCSV
function, or edit what happens when you click the Download CSV
menu item.
An example of editing what happens when you click the menu item (JSFiddle):
menuItems: [{
textKey: 'downloadCSV',
onclick: function () {
var csv = this.getCSV(true);
csv += '\n"My source 1","My source 2","My source 3"';
this.fileDownload(
'data:text/csv,\uFEFF' + encodeURIComponent(csv),
'csv',
csv,
'text/csv'
);
}
}]
An example of extending Highcharts (JSFiddle):
(function (H) {
H.wrap(H.Chart.prototype, 'getCSV', function (proceed, useLocalDecimalPoint) {
// Run the original proceed method
result = proceed.apply(this, Array.prototype.slice.call(arguments, 1));
result += '\n"My source 1","My source 2","My source 3"';
return result;
});
}(Highcharts));
Upvotes: 2