score:0
Yes, it has to do with the animation. You need to check for the animation being complete. Under options add:
animation: {
onComplete: done
}
and then create a function "done" where you handle the printing.
function done() {
}
score:1
Try using the .toDataURL()
method on your canvas. This method returns a URL containing your chart as an image.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL
Grab your pie chart's canvas and convert it to an image:
document.getElementbyId('pieChart').toDataURL;
Assign the generated chart image URL to a variable, let's keep using
printContents
in this case:let **printContents** = document.getElementbyId('pieChart').toDataURL;
Initiate an html document on the fly and append the previously created image URL as an
<img>
element's source, usingtemplate literals
to embed the printContents variable: let html =<html><head><title></title></head><body><img src=${printContent}></body></html>
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
-Execute the print job (Chrome) by writing the previously constructed html doc to the print window on the fly:
let **printWindow** = window.open('', 'Print-Preview', 'height=900,width=200');
printWindow.document.open();
printwindow.document.write(html);
printWindow.document.close();
Source: stackoverflow.com
Related Query
- Print pie chart in chartjs
- Chartjs random colors for each part of pie chart with data dynamically from database
- chartjs datalabels change font and color of text displaying inside pie chart
- Display values outside of pie chart in chartjs
- ChartJS 2.0 - Huddle labels on pie chart
- Angular 8 & ChartJs change color in pie chart
- Pie chart is not getting rendered in ChartJS
- ChartJS Doughnout Chart Pie Offset on Hover
- Custom data in label on ChartJS pie chart
- ChartJs - Pie Chart - how to remove labels that are on the pie chart
- Use transparent stroke color with chartjs pie chart
- ChartJS version 3 how to add percentage to pie chart tooltip
- canvas fill text vanishes when hovering over chartjs pie chart
- chartjs Adding percentages to Pie Chart Legend
- Hide labels from pie chart in chartjs
- How to get labels on ChartJS Pie chart segments
- How can I change the cursor on pie chart segment hover in ChartJS 3?
- ChartJS pie chart with simple parsing options doesn't render, only works when set as bar/line chart
- How to make chartjs pie chart responsive
- How to group smaller Pie Chart slices together to Improve Readability in chartjs
- Make chartjs pie chart wiyh dynamic data
- how to display name on multi series pie chart in chartjs
- Legend color not working with randomly generated background colors in chartjs pie chart
- ChartJS Pie Chart How default just show 2 legend datas
- How to print a chart rendered by code
- chartJS pie chart not updating after axios GET
- Show/hide All nested data in ChartJS Pie chart when outer is shown/hidden
- How to set up a simple pie chart using React in ChartJS on codesandbox
- ChartJS - How to add Text between Pie Chart and Legend
- Can't draw pie chart using chartjs - TypeError: Cannot create property '_meta' on number '16'
More Query from same tag
- ChartJs - displaying data dynamically from back-end
- chartnew.js - remove lines from pie chart on 100%
- chart.js uncaught reference error while updating
- Get Value for point clicked on Pie Chart in Chart.js 3
- setting QuickCharts color
- Showing border for columns in barchart of chart js on hover?
- chart.js with json data and jquery - error :-(
- Chart JS + Laravel - How to add 0 to array
- Chart.js minimal width of Chart with scrollable overflow
- How to make aspecific API call from within a Line Chart class in ReactJS using react-chartjs-2?
- ChartJS: Draw line between two data points on hover
- chart.js not working in browser with django. no error for template and static folder setting
- How to execute a JavaScript function with ChartJS and FreeMarker?
- Chartjs radar indexed labels
- Chart.js doughnut chart tooltip size?
- How can i create a background of moving graphs like chartsjs?
- Setting default to 0 in vuechart.js HorizontalBar
- Ionic/Chart.js - Cannot read property 'nativeElement' of undefined
- Displaying Charts in C# using ChartJS
- chart.js - tooltip callback function ignore hidden datasets when deselecting legend
- How to adjust the Js Chart's label?
- Chart.js angular8 Y axis ticks
- How can i fix my code so i can read my data
- ChartJS v2 - Outer arc when hover on a pie/doughnut segment
- Use transparent stroke color with chartjs pie chart
- Pass Ajax response array to Chart.js
- Add labels to bar chart: chartjs
- Chart.js canvas keeps shifting upwards if I add things below it? (Angular - Chart.JS - NG2Charts)
- charts.js fixed y label to 8 decimals
- Chart.js: adding a custom label to each item, and displaying it with a custom tooltip