Apexcharts.js: Method dataURI() returns a blank chart as the base64

Created on 27 Mar 2019  路  2Comments  路  Source: apexcharts/apexcharts.js

Hello, i'm using dataURI method to get the base64 to use with jsPDF.

My chart:
2019-03-27_11-15-12

dataURI generated: https://paste.in/6llDep
dataURI image:
2019-03-27_11-18-09

My javascript code:

var options = {
    chart: {
        width: '100%',
        height: '400px',
        type: 'pie'
    },
    labels: chartLabels,
    series: chartData,
    responsive: [{
        breakpoint: 480,
        options: {
            chart: {
                size: '100%'
            },
            legend: {
                position: 'bottom'
            },
            dataLabels: {
                enabled: true,
                formatter: function (val) {
                    return val + "%"
                }
            }
        }
    }]
};

chart = new ApexCharts(
    document.querySelector("#myChart"),
    options
);

chart.render();

var dataURL = chart.dataURI().then((uri) => {
    console.log(uri);
});

Am i doing something wrong?

Best regards.

bug

Most helpful comment

You should wait for the animation to complete before you can grab the image.

Hence, you should put your dataURI() function after render() has finished.

chart.render().then(() => {
    window.setTimeout(function() {
        chart.dataURI().then((uri) => {
            console.log(uri);
        })
    }, 1000) 
})

I have put a timer currently, as chart resolves promise before the animation ends. I will fix this bug and then you won't have to use the timer.

All 2 comments

You should wait for the animation to complete before you can grab the image.

Hence, you should put your dataURI() function after render() has finished.

chart.render().then(() => {
    window.setTimeout(function() {
        chart.dataURI().then((uri) => {
            console.log(uri);
        })
    }, 1000) 
})

I have put a timer currently, as chart resolves promise before the animation ends. I will fix this bug and then you won't have to use the timer.

Thank you so much for your support.

It's working now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thellimist picture thellimist  路  3Comments

EroTiXx picture EroTiXx  路  3Comments

jeroenpol picture jeroenpol  路  3Comments

Sumon-miazi picture Sumon-miazi  路  3Comments

cstlaurent picture cstlaurent  路  3Comments