使用canvasjs和jspdf生成圖表並導出爲pdf。圖表正在生成,但導出爲PDF不工作。我在這裏錯過了什麼,如果有人可以建議。您的時間將不勝感激。謝謝使用canvasjs和jspdf生成圖表並使用canvas生成圖表並導出爲PDF格式的pdf生成器
。
<head>
<title>Graphical Representation Of Stores</title>
<style type="/css">
</style>
<script type="text/javascript" src="canvasjs.min.js"> </script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.min.js"></script>
</head>
<body>
<form>
<div id="chartContainer" style="height: 360px; width: 100%;"></div>
<button id="exportButton" type="button">Export as PDF</button>
<script type="text/javascript">
var chart = new CanvasJS.Chart("chartContainer",
{
title: {
text: "Exporting chart using jsPDF & toDataurl"
},
data: [
{
type: "spline",
dataPoints: [
{ x: 10, y: 4 },
{ x: 20, y: 7 },
{ x: 30, y: 2 },
{ x: 40, y: 3 },
{ x: 50, y: 5 }
]
}
]
});
chart.render();
var canvas = $("#chartContainer.canvasjs-chart-canvas").get(0);
var dataURL = canvas.toDataURL();
//console.log(dataURL);
$("#exportButton").click(function(){
var pdf = new jsPDF();
pdf.addImage(dataURL, 'JPEG', 0, 0);
pdf.save("download.pdf");
});
</script>
</form>
</body>
</head>
</html>
歡迎來到SO。請看[旅遊](http://stackoverflow.com/tour)。發佈您收到的錯誤。儘可能具體,因爲它會導致更好的答案。 –