You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there an easy way to export structured graph data as CSV file from within graph via java script - eg. right click on graph and select export data or clicking on particular part of graph.
/** Convert a 2D array into a CSV string
*/
function arrayToCsv(data){
return data.map(row =>
row
.map(String) // convert every value to String
.map(v => v.replaceAll('"', '""')) // escape double colons
.map(v => "${v}") // quote it
.join(';') // semi-comma-separated
).join('\r\n'); // rows starting on new lines
}
No, there is not a simple way to do this. The easiest way is to add a link to a separate PHP script that would generate the CSV from the same data you pass into SVGGraph. You can probably find a decent CSV output library on Packagist to help with that.
Is there an easy way to export structured graph data as CSV file from within graph via java script - eg. right click on graph and select export data or clicking on particular part of graph.
bellow and js example:
let csv = arrayToCsv([
[1, '2', '"3"'],
[true, null, undefined],
]);
downloadBlob(csv, 'export.csv', 'text/csv;charset=utf-8;')
/** Convert a 2D array into a CSV string
*/
function arrayToCsv(data){
return data.map(row =>
row
.map(String) // convert every value to String
.map(v => v.replaceAll('"', '""')) // escape double colons
.map(v =>
"${v}"
) // quote it.join(';') // semi-comma-separated
).join('\r\n'); // rows starting on new lines
}
/** Download contents as a file
*/
function downloadBlob(content, filename, contentType) {
// Create a blob
var blob = new Blob([content], { type: contentType });
var url = URL.createObjectURL(blob);
// Create a link to download it
var pom = document.createElement('a');
pom.href = url;
pom.setAttribute('download', filename);
pom.click();
}
The text was updated successfully, but these errors were encountered: