简体   繁体   English

如何在Phonegap应用程序中将渲染的Highchart图表导出为pdf / png / jpeg?

[英]How to export rendered Highchart chart as a pdf/png/jpeg in a Phonegap application?

I am trying to use 我正在尝试使用

chart.exportChart({
  type: 'application/pdf',
  filename: 'my-pdf'
});

in a Phonegap application with no success, although all is working fine in the browser. 在Phonegap应用程序中没有成功,尽管在浏览器中一切正常。

My Problem: 我的问题:

I want to attach the rendered chart as a pdf/png/jpeg in the iOS email client. 我想在iOS电子邮件客户端中将呈现的图表附加为pdf / png / jpeg。 How is it possible to save the downloaded content using chart.exportChart or any other way to the iOS Application Sandbox? 如何使用chart.exportChart或任何其他方式将下载的内容保存到iOS应用程序沙箱? Should I give the App Sandbox path in the filename key of the chart.exportChart method? 是否应在chart.exportChart方法的filename键中提供“应用程序沙箱”路径?

Here is wat i tried: (I am on cordova-1.6.1.js) 这是我尝试过的wat :(我在cordova-1.6.1.js上)

window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSys, fail);


function fail() {

}

function gotFileSys(fileSystem) {
    chart.exportChart({
       type: 'application/pdf',
    filename: fileSystem.root.fullPath+"/my-pdf"
    });
}

The above dosen't work and console says- 上面的没用,控制台说-

[INFO] Error in success callback: File1 = TypeError: 'undefined' is not a function [INFO]成功回调中出错:File1 = TypeError:'undefined'不是一个函数

PS: The way I tried is an act of Desperation :( PS:我尝试的方式是一种绝望的行为:(

Could do it like this- 可以这样-

canvg(document.getElementById('canvas'), chart.getSVG());
var canvas = document.getElementById("canvas") ; 
var img = canvas.toDataURL("image/png").replace("data:image/png;base64,", ""); //img is base64 encoded and can be persisted in the App Sandbox.

Will need to write a PhoneGap plugin and use Matt's Category to convert base64 encoded img into an image and save the binary in the App Sandbox. 将需要编写一个PhoneGap插件,并使用Matt的Category将base64编码的img转换为图像,并将二进制文件保存在App Sandbox中。

canvg scripts are available at here and here shall be included in the markup as well. canvg脚本可在这里 ,并在这里应包括在标记为好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM