amcharts / export

Apache License 2.0
56 stars 33 forks source link

Failed to export Base64 representation of chart image #70

Closed raufemm closed 6 years ago

raufemm commented 6 years ago

I need to implement this: https://www.amcharts.com/kbase/get-base64-representation-chart-image/

Unfortunelly an error appers when chart["export"].capture is executed,

"Uncaught TypeError: chart.export.capture is not a function"

Below is my javascript code:

`var varCriticidadeVulnerabilidade = undefined; var chart = undefined; function carregaConfiguracaoGraficoItem35() { configuracao = { "type": "serial", "dataProvider": varCriticidadeVulnerabilidade,

            "graphs": [{
                "balloonText": "[[category]]: <b>[[value]]</b>",
                "colorField": "color",
                "fillAlphas": 1,
                "lineAlpha": 0.1,
                "type": "column",
                "valueField": "value"
            }],

            "startEffect": "bounce",
            "innerRadius": "30%",
            "startDuration": 2,

            "depth3D": 20,
            "angle": 30,
            "categoryField": "key",
            "categoryAxis": {
                "gridPosition": "start",
                "labelRotation": 0,
                "fontSize": 9
            },
            "export": {
                "enabled": true,
                "menu": []
            }
        };

        return configuracao;
    }`

`$(document).ready(function () {

        $("#ddlProjeto").change(function () {

            var urlPage = window.location.href + "/CarregaDadosGraficoRelatorio";

            var nrseq = $("#ddlProjeto").val();

            $.ajax({
                type: "POST",
                url: urlPage,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: JSON.stringify({ nrseq: nrseq }),
                async: true,
                success: function (result) {

                    varCriticidadeVulnerabilidade = JSON.parse(result.d);

                    configuracao = carregaConfiguracaoGraficoItem35();
                    chart = AmCharts.makeChart("chartdiv", configuracao); //works fine

                    chart["export"].capture({}, function () { // do not work

                        // SAVE TO PNG
                        this.toPNG({}, function (base64) {

                            // We have now a Base64-encoded image data
                            // which we can now transfer to server via AJAX
                            // i.e. jQuery.post( "saveimage.php", { "data": base64 } )
                            console.log(base64);
                        });
                    });
                }
            })

        })
    });`

Can you help me?

dmitrystril commented 5 years ago

@raufemm Have you ever managed to fix this?