Reputation: 43
I want to modify csv data while export from amcharts. Scenario is like : I have 2 column 1 with values and other with 0. Now i dont want that column to display in the csv which have 0 values.
I did not find anything for this.
Upvotes: 2
Views: 1840
Reputation: 1511
The processData
way is fine for datas that do not much differ to the dataProvider
.
Amcharts's doc is not very well documented about this, but after a bit of digging, I found this way :
var myChart = AmCharts.makeChart('chart-id', {
dataProvider: myDatas, // Some datas
export: {
enabled: true,
// Using the 'menu' option in order to override its behavior ...
menu: [{
class: 'export-main',
menu: [{
label: 'Download as ...',
menu: ['PNG', 'JPG', 'SVG', 'PDF']
}, {
label: 'Save as ...',
menu: [{
label: 'CSV',
// Overriding CSV export behavior :
click: function exportCSV() {
// This will export the 'myDatas' datas to a string formatted as a CSV.
// Feel free to change the 'data' option of the 'toCSV()' method for a different CSV.
myChart.export.toCSV({ data: myDatas }, function(data) {
// 'data' is a string containing the CSV
// This will download the CSV to the file MyCSV.csv !
this.download(data, this.defaults.formats.CSV.mimeType, 'MyCSV.csv');
});
}
}]
}, {
label: 'Annotate ...',
action: 'draw',
menu: [{
class: 'export-drawing',
menu: ['PNG', 'JPG']
}]
}]
}]
}
});
This will export and download a CSV file with the desired datas !
Upvotes: 1
Reputation: 6162
You could use processData
for that. See more here: https://github.com/amcharts/export#changing-the-dataprovider-when-exporting
"export": {
"enabled": true,
"processData": function (data, cfg) {
if (cfg.format === 'CSV') {
return data.map(function (item) {
// Ignore the second column
return {
firstColumn: item.firstColumn
};
});
}
return data;
}
}
Upvotes: 1