How to print angular-chart

3.4k Views Asked by At

I am using "angular-chart.js"

and want to print this chart. My code is,

<html>
<head>Chart</head>
<body>
    <div class="row"><b>Patient Report</b>
        <div>
            <canvas id="line" class="chart chart-line" data="agedata" colours="colours"
                labels="labels" legend="true" series="series"click="onClick"></canvas>
        </div>
    </div>
    <div class="row">
        <a href="javascript:window.print()" class="btn btn-success">Print</a>
    </div>
</body>

But it prints nothing. Can Anyone suggest me methods to print chart?

2

There are 2 best solutions below

0
On BEST ANSWER

You can use the toDataURL() to make the canvas into an image (and you could use media specific CSS to hide the canvas and swap in the img with src as the Data URL when printing)

Remember to wait for the animation to end before generating the data URI or you end up with a blank image.

0
On

Chart.js relies on a HTML5 canvas to render its charts however canvas objects cannot be printed by browsers.

The solution to bypass this limitation is to transform the canvas into an image when printing as described in this post.