如何使用我的图表宽度为ngPrint
的tc-angular-chartjs库进行打印 <div id="printThisElement" ng-controller="AppController">
<canvas tc-chartjs-line chart-options="options" chart-data="data" auto-legend ng-click="chartClick($event)" chart="chart"></canvas>
<button class="btn btn-primary" ng-print print-element-id="printThisElement">
<i class="fa fa-print"></i> Print
</button>
</div>
你能看到我解释它的例子吗?
http://jsfiddle.net/0ow8rpuv/
一些建议?
答案 0 :(得分:1)
最明显的解决方案是:
至少可以说,有些人可能认为这个解决方案很乏味。我希望有更多知名人士可以提出更优雅的东西。
代码相关(普通JS):
let canvas = document.getElementById('your-canvas'); // Grab canvas from DOM
let ctx = canvas.getContext('2d'); // Grab 2D context from canvas
let image = ctx.toDataUrl(); // You can look-up some decorations for this
let newImage = document.createElement('img'); // Create a new image element
newImage.src = image;
// You can customize the size and the styles of the image to print here
document.appendChild(newImage); // Append the new image to the DOM to print it later. Through CSS styles, you can also force the browser to print only that specific image. As usual, read the docs