简体   繁体   English

将dygraph图表保存到我本地硬盘上的jpg图像中

[英]save dygraph chart into jpg image on my local hard drive

I am working with JavasSript Dygraphs chart. 我正在使用JavasSript Dygraphs图表。 Everything is fine but what i need to do is to be able to save it on my local hard drive as an image. 一切都很好,但我需要做的是能够将它作为图像保存在我的本地硬盘上。 Below is my JavaScript code: 以下是我的JavaScript代码:

<script type="text/javascript">
 var img;
  g3 = new Dygraph(
   img = document.getElementById("graphdiv3"),
    "temperatures.csv",
    {
       rollPeriod: 9,
       showRoller: true,  
    }
    );
</script>

Here is my HTML code: 这是我的HTML代码:

 <div>
     <div id='graphdiv3'></div>
 </div>

You can create a hidden image element in your page and export the image to the users disk but the issue is the downloaded file will not have any filetype. 您可以在页面中创建隐藏的图像元素并将图像导出到用户磁盘,但问题是下载的文件没有任何文件类型。 The user can open the downloaded file in any image viewer. 用户可以在任何图像查看器中打开下载的文件。

var img = document.getElementById(imgId);
Dygraph.Export.asPNG(graph, img);
window.location.href = img.src.replace('image/png','image/octet-stream');

This uses the dygraph-export library from this link http://cavorite.com/labs/js/dygraphs-export/ 这使用此链接中的dygraph-export库http://cavorite.com/labs/js/dygraphs-export/

没有正式的方法可以做到这一点,但是dygraphs用户已经做了一些工作: https ://groups.google.com/d/topic/dygraphs-users/whcMjtBE7s0/discussion

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

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