Javascript 使用jquery自动触发单击以将所有图形导出为图像

Javascript 使用jquery自动触发单击以将所有图形导出为图像,javascript,php,jquery,html,amcharts,Javascript,Php,Jquery,Html,Amcharts,我在一个html页面中有多个图形。我正在尝试在该页面上的所有图形完成加载后导出所有图形。 我有触发点击事件的脚本,但它没有按我想要的那样工作。 我想触发click按钮,这样它就可以将图形图像按base64编码的方式放入数组中,然后将数据发送到php文件并将其保存为图像 正在创建两个映像,但只有一个映像正确,而另一个映像已损坏 以下是我生成图形的代码: 以下是我的php文件代码: <?php $data = urldecode($_POST['imageData']); list($typ

我在一个html页面中有多个图形。我正在尝试在该页面上的所有图形完成加载后导出所有图形。 我有触发点击事件的脚本,但它没有按我想要的那样工作。 我想触发click按钮,这样它就可以将图形图像按base64编码的方式放入数组中,然后将数据发送到php文件并将其保存为图像

正在创建两个映像,但只有一个映像正确,而另一个映像已损坏

以下是我生成图形的代码:

以下是我的php文件代码:

<?php
$data = urldecode($_POST['imageData']);
list($type, $data) = explode(';', $data);
list(, $data)      = explode(',', $data);
$data = base64_decode($data);
$filename = "images/image".rand(1000,10000).".jpg";
file_put_contents($filename, $data);
?>

任何其他方法也可能有效。

不会调用sendAllData()。所以我提出了一些改变,这不是一个完整的解决方案,但对你有帮助

$('*').click(function(e){
    sendAllData();
});



function sendAllData(){
    console.log(dataArray);
    var arsize = dataArray.length;
    console.log("here");
    //execute this function and use the dataArray here  
    //send data to php file
    if(arsize != 0){
       for(i=0;i<=dataArray.length;i++){
          jQuery.post( "a.php", {imageData: encodeURIComponent( dataArray[i] )})
               .done(function( data ) {
                   if(data != 1){
                       console.log( "Data Loaded: " + data );
                   }else{
                       console.log("error");
                   }
          });
        }
    }
}
$('*')。单击(函数(e){
sendAllData();
});
函数sendAllData(){
log(数据数组);
var arsize=dataArray.length;
console.log(“此处”);
//执行此函数并在此处使用dataArray
//将数据发送到php文件
如果(arsize!=0){

对于(i=0;i而言,更好的方法是只在AmCharts的事件中使用API方法,AmCharts导出插件API而不是使用假点击,类似于中的第一个示例。它使用
呈现的
事件,但
动画完成的
也可以:

"listeners": [{
  "event": "animationFinished",
  "method": function(e) {
    //wait for fabric
    var interval = setInterval(function() {
      if (window.fabric) {
        clearTimeout(interval);
        e.chart.export.capture({}, function() {
          this.toJPG({}, function(data) {
             //post base64 string in data to your endpoint directly
          });
        });
      }
    });
  }
]

-请注意,出于调试目的,我将导出的图像添加到屏幕底部以验证其是否有效。

我尝试调用它..不工作..因此我临时删除了代码。请在您的机器上尝试代码并指导我好吗?非常感谢。您刚刚救了我。
"listeners": [{
  "event": "animationFinished",
  "method": function(e) {
    //wait for fabric
    var interval = setInterval(function() {
      if (window.fabric) {
        clearTimeout(interval);
        e.chart.export.capture({}, function() {
          this.toJPG({}, function(data) {
             //post base64 string in data to your endpoint directly
          });
        });
      }
    });
  }
]