2012-07-17 94 views
3

我正在使用JavasSript Dygraphs圖表。一切都很好,但我需要做的是能夠將它保存在本地硬盤上作爲圖像。下面是我的JavaScript代碼:將dygraph圖表保存爲本地硬盤上的jpg圖像

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

這裏是我的HTML代碼:

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

回答

3

您可以在頁面中創建隱藏的圖像元素並將圖像導出到用戶磁盤,但問題是下載的文件不會有任何文件類型。用戶可以在任何圖像查看器中打開下載的文件。

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

它使用dygraph出口圖書館從這個鏈接http://cavorite.com/labs/js/dygraphs-export/

相關問題