score:4
your best bet is probably to render the chart as an image with a javascript-enabled renderer, and then add that image to your pdf.
option 1: if you want to stick with headless rendering, you may need to add a --no-stop-slow-scripts
option in addition to the javascript delay (could also check out puppeteer, an alternative renderer).
option 2: use a service that renders charts to image or pdf. quickchart is an open-source web service that does this (i am one of its maintainers).
for example, take your chart.js config:
$chartconfig = '{
"type": "bar",
"data": {
"labels": [2012, 2013, 2014, 2015, 2016],
"datasets": [{
"label": "users",
"data": [120, 60, 50, 180, 120]
}]
}
}';
pack it into a url with the /chart
endpoint:
$charturl = 'https://quickchart.io/chart?w=500&h=300&c=' . urlencode($chartconfig);
and then include the resulting url as an image in your wkhtmltopdf page:
<img src="https://quickchart.io/chart?w=500&h=300&c=%7b%0a++%22type%22%3a+%22bar%22%2c%0a++%22data%22%3a+%7b%0a++++%22labels%22%3a+%5b2012%2c+2013%2c+2014%2c+2015%2c+2016%5d%2c%0a++++%22datasets%22%3a+%5b%7b%0a++++++%22label%22%3a+%22users%22%2c%0a++++++%22data%22%3a+%5b120%2c+60%2c+50%2c+180%2c+120%5d%0a++++%7d%5d%0a++%7d%0a%7d" />
this will render your chart without any javascript.
if you want an even simpler way and you're ok with a pdf that shows only the chart, add &format=pdf
to the url and the service will directly generate a pdf of your chart: example pdf
note that you can self-host the chart render web service if necessary.
Source: stackoverflow.com
Related Query
- How to generate chartjs charts to pdf using laravel?
- How to display chart using Chartjs with JSON data in Laravel
- How to generate color code dynamically by swapping 2 characters within a string using PHP
- Generate PDF from HTML page made with Bootstrap and ChartJS in Laravel
- Is it possible to generate multiple chart in Laravel using chartjs ? If possible please give the solution
- How to generate dynamic bar chart in laravel using chart.js
- How to run Chart.js samples using source code
- How to modify bar width in Chartjs 2 bar charts
- How to save Chart JS charts as image without black background using blobs and filesaver?
- How to add images as labels to Canvas Charts using chart.js
- How to zoom charts in chart.js using angular 7
- How to access labels array using chart plugin (Chart.pluginService.register) in Chartjs 2.x?
- How to work out Chartjs using TypeScript with Chartjs.definitelyTyped from github
- How do I make line charts overlay over bar charts in chartjs
- how to reset the graph/chart after zoomin, pan using chartjs
- How to add ChartJS code in Html2Pdf to view image
- How to create a stacked graph using ChartJS
- How to create a rounded rectangle using ChartJS
- How to install chartjs on laravel 6 via npm
- How to use chartjs-plugin-datalabels for specific charts using vue-chart.js
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
- chartjs - how to set the order in which the different charts are displayed
- ChartJS / Chartjs-plugin-annotation How to draw multiple vertical lines using an array?
- how to show labels in laravel charts when the name of the label is on another table?
- How can I load multiple Chartjs charts with different data on the same page?
- how to put a y-axis and x-axis label while using html and chartjs
- How to have mutiple charts in a single page using Chart.js?
- how can i send a list of numbers from views.py to a chartjs file im using for the front?
- Generate multiple line charts in Django with ChartJS
- How to export a chart in Excel and PDF format using Chart.js
More Query from same tag
- Removing axes lines on chart.js
- Can "Bar" be placed center of vertical grid line in Chart.js?
- ChartJS custom tooltip doesn't render background on labels (only the title)
- Check if element exists before trying to call getContext
- Tick - no negative
- chart.js 2.0 add new property to dataset
- Chart.js onClick function for bar graph
- How to shorten Chart.js label
- Chart.js showing old chart on hover
- Format chart.js x labels
- issue with customisation of Chart new.js for bar chart
- How can i give the full Legend a background color in chart js?
- Remove/Hide (display:none) the graphical chart in small-mobile view - JS chart
- onHover event is not triggering in chart.js
- Changing labels with logo images
- Razor chart.js labels/data not in sync
- How to can I get text inside a chats.js circular chart
- How to display currency in Chart js
- Chart.js legend customisation
- format JSON data for chart.js from Angular 4 observable
- Chart Piechart in only show percentage on hover but it shows data and label with percentage both i just want to show percentage only percentage
- Cannot create chart on react element
- How to load Json data onto a Charts.js chart
- I'm trying to get data from flask app but I get this "Uncaught ReferenceError: _data is not defined"
- Plotting objects in Chart.js
- Display values outside of pie chart in chartjs
- Chart.js xAxis linear scale : strange behavior
- Chart.js dynamic bar width
- How to Change the Label Strike-Through with light gray on a ChartJS Doughnut?
- Add buffer to Y axis with chart js