Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporting without amcharts #18

Closed
piernik opened this issue Sep 14, 2015 · 6 comments
Closed

Exporting without amcharts #18

piernik opened this issue Sep 14, 2015 · 6 comments

Comments

@piernik
Copy link

piernik commented Sep 14, 2015

This plugin works great and I was wondering weather it can be used as a standalone script for exporting purposes.
Example I have my own table with data and want to export it to csv or excel or even PDF. Can I use this script somehow?

@maertz
Copy link
Collaborator

maertz commented Sep 15, 2015

Sure, ensure to serve the 'AmCharts' namespace within the 'window' object before you include the export resources. Once you have all that you are ready to create your export instance and generate the files like following:

<script type="text/javascript">
    // Server namespace with required variables
    window.AmCharts = {
        translations: {},
        addInitHandler: function() { /* NOOP */ }
    };
</script>

<script type="text/javascript" src="http://amcharts.com/lib/3/plugins/export/export.js"></script>

<!-- REQUIRED FOR EXCEL -->
<script type="text/javascript" src="http://amcharts.com/lib/3/plugins/export/libs/jszip/jszip.js"></script>
<script type="text/javascript" src="http://amcharts.com/lib/3/plugins/export/libs/xlsx/xlsx.js"></script>

<!-- REQUIRED FOR DOWNLOAD -->
<script type="text/javascript" src="http://amcharts.com/lib/3/plugins/export/libs/FileSaver.js/FileSaver.js"></script>

<!-- ACTUAL MAGICAL PART -->
<script type="text/javascript">

    // CREATE EXPORT INSTANCE
    var ame = new AmCharts.export({},{
        // Export settings
    });

    // DATA ARRAY
    var data = [ {"country": "USA","visits": 2025}, {"country": "China","visits": 1882}, {"country": "Japan","visits": 1809}, {"country": "Germany  ","visits": 1322}, {"country": "UK","visits": 1122}, {"country": "France","visits": 1114}, {"country": "India","visits": 984}, {"country": "Spain","visits": 711}, {"country": "Netherlands","visits": 665}, {"country": "Russia","visits": 580}, {"country": "South Korea","visits": 443}, {"country": "Canada","visits": 441}, {"country": "Brazil","visits": 395} ];

    // CONVERT DATA TO CSV
    ame.toCSV({
        data: data

    // CONVERT CALLBACK
    },function(output) {
        var info = this.defaults.formats.CSV;
        var filename = this.config.filename + "." + info.extension;
        var mimetype = info.mimeType;

        // OFFER OUTPUT AS DOWNLOAD
        this.download(output,mimetype,filename);
    });
</script>

@piernik
Copy link
Author

piernik commented Sep 15, 2015

Thank very much - I'll try it tommorow. You should think of releasing Your plugin as a standalone script - it's great

@mg1075
Copy link

mg1075 commented Sep 15, 2015

That would be nice - I thought this was not possible, as per an earlier question.
#10

@maertz
Copy link
Collaborator

maertz commented Sep 15, 2015

@mg1075 it is still not possible to capture the whole HTML document. Although it's possible to process custom data as mentioned above, since we've exposed the API constructor few versions ago and enhanced the internal data management. Excuse me loosing your subject since I've released that version.

@piernik Thanks, let's see what shows up in the feature ;)

@mg1075
Copy link

mg1075 commented Apr 17, 2017

@maertz - For clarification: is it only possible to expert data for a non-amcharts element, or is it also possible to use the plugin to export non-amcharts document elements? E.g., if a person wanted to export part of the page as PDF, PNG, JPG, or SVG, would the plugin make this now possible?

@maertz
Copy link
Collaborator

maertz commented Apr 19, 2017

Only non-amcharts data can be exported through the approach mentioned above. Visual data is not possible (non-amcharts elements), therefore html2canvas might be an option for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants