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
Galaxy j7 2015
I don't know what is the main problem of it. Any help would be highly appreciated.
This plugin should help you save your image as a download file.
Prodvided your canvas is "myCanvas":
Canvas2Image.saveAsPNG(myCanvas, width, height)
or
Canvas2Image.saveAsJPEG(myCanvas, width, height)
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
When you tap the download option canvasJS is using the HTML5 download attribute to trigger the download, which works well in browsers that support it.
However when you tap the same link within your Cordova application, the webview it's running inside of doesn't know how to handle file downloads. Therefore nothing happens.
It looks like you could potentially enable this feature yourself by adding some custom Java to the app. Unfortunately I'm not an Android Java developer, but this issue might help you out - Download File inside WebView
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With