Home › Forums › Chart Support › Xport Multiple Series Graph as CSV › Reply To: Xport Multiple Series Graph as CSV
It is possible to convert chart data into comma-separated CSV and download it with a few lines of code. Please find the code snippet for the same below,
function convertChartDataToCSV(args) {
var result = '',
ctr, keys, columnDelimiter, lineDelimiter, data;
data = args.data || null;
if (data == null || !data.length) {
return null;
}
columnDelimiter = args.columnDelimiter || ',';
lineDelimiter = args.lineDelimiter || '\n';
var mergedData = mergeData(data);
keys = Object.keys(mergedData[0]);
result = '';
result += keys.join(columnDelimiter);
result += lineDelimiter;
mergedData.forEach(function (item) {
ctr = 0;
keys.forEach(function (key) {
if (ctr > 0) result += columnDelimiter;
result += (typeof (item[key]) != undefined ? item[key] : "");
ctr++;
});
result += lineDelimiter;
});
return result;
}
Please take a look at this JSFiddle for working code. Also take a look at this 3rd party plugin, which seems to be working with multi-series chart as well.
Considering this thread as a duplicate of Question about Multi Series Graph CSV Export and hence closing the same.
—
Adithya Menon
Team CanvasJS