Search code examples
javascriptandroidcanvasjs

Canvas js export enable not working on android device


I am working on CANVASjS and build a sample app which is displaying data on chart. I have enabled export to save chart in .png and .jpeg and print also. While deploying it on ripple emulator the export is working perfect but when i deploy it on my android device it's not working. Below is the code part in which i have enabled export.

var chart = new CanvasJS.Chart("container", {
            zoomEnabled: true,
            zoomType: "xy",
            animationEnabled: true,
            animationDuration: 2000,
            exportEnabled: true,
// all other chart code 
});

Update 1:

 function drawChart(data)
            {
                var chart = new CanvasJS.Chart("container", {
                    zoomEnabled: true,
                    zoomType: "xy",
                    animationEnabled: true,
                    animationDuration: 2000,
                    exportEnabled: true,
                    exportFileName: "Column Chart",
                    title: {
                        text: "Energy vs Date Time"
                    },
                    axisY: {
                        title: "EnergykWh",
                        interlacedColor: "#F8F1E4",
                        tickLength: 10,
                        suffix: "k",
                    },
                    legend: {
                        cursor: "pointer",
                        itemclick: function (e) {
                            if (typeof (e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
                                e.dataSeries.visible = false;
                            } else {
                                e.dataSeries.visible = true;
                            }
                            e.chart.render();
                        }
                    },
                    dataPointWidth: 20,
                    data: [{
                        //legendText: "EngergykWh",
                        showInLegend: true,
                        type: 'column',
                        //xValueType: "dateTime",
                        xValueFormatString: "DD/MMM/YYYY h:mm TT",
                        //xValueFormatString: "YYYY-MM-DD hh:mm:ss TT",
                        showInLegend: true,
                        name: "series1",
                        legendText: "EnergykWh",
                        dataPoints: data                          
                    }]
                });

                chart.render();
            }

Update 2:

Bellow are the info images and a link of OS versions of android devices on which i have tried

enter image description here

enter image description here

Galaxy j7 2015

I don't know what is the main problem of it. Any help would be highly appreciated.


Solution

  • There is no Download Manager in webview that you have created, so you need to handle the download functionality manually. There are 2 ways to download a file from webview.

    1.Using Android Download Manager

    2.Using web browser opened from webview (which internally uses Android Download Manager)

    The required permission includes WRITE_EXTERNAL_STORAGE

    Then set a download-listener for webview.

    webView.setDownloadListener(new DownloadListener(){
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength){
            //for downloading directly through download manager
            Request request = new Request(Uri.parse(url));
            request.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
            request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "download");
            DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
            dm.enqueue(request);
        }
    });
    

    Refer the following Links for more info: Link 1, Link2, Link 3, Link4