Hello!
I have a problem with adding a chart to PDF. I want to put a chart in my Raport in PDF for a client but I haven't had any achievements in this field for several days. This is the last thing I need to do.
I'm using HTML-PDF as described in Make a PDF file.
Is there any way to achieve it? The tables and other data is adding correctly, but I don't know how to add a chart. I didn't find nothing that works in Google or this forum
This is my flow:
[{"id":"cd687ea2.91d25","type":"HTML-PDF","z":"74c70725.489d28","name":"HTML-PDF","output":"file","x":1170,"y":2260,"wires":[["407ee87d.6a5398"]]},{"id":"407ee87d.6a5398","type":"debug","z":"74c70725.489d28","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1290,"y":2320,"wires":[]},{"id":"5a30ad2a.86e374","type":"inject","z":"74c70725.489d28","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":300,"y":2260,"wires":[["7161974c.6e8ec8","78005aa7.2aea84"]]},{"id":"7161974c.6e8ec8","type":"function","z":"74c70725.489d28","name":"contents","func":"//globals\nvar CompanyName = \"CompanyName\";\nvar CompanyLogoURL = \"https://dynamic.brandcrowd.com/asset/logo/522494d1-50ee-4316-bbc9-58b1f90bab5e/logo?v=4\";\n\n//flow variables\nvar startdate = 1578485832986; //date in unix timestamp\nvar enddate = 1578485832986 + 24*60*60*1000; //next day ;)\nvar selected_machine = \"MachineName\";\nvar selected_machine_name = \"MachineName2\";\n\nvar content_var_prod_mean = 123;\nvar content_var_prod_max = 456;\nvar content_var_prod_min = 789;\nvar content_var_prod_sum = 1233;\n\nvar content_var_inac_count = 2;\nvar content_var_inac_sum = 5;\nvar content_var_inac_mean = 7;\n\n\nvar options = {year: 'numeric', month: '2-digit', day: '2-digit'};\nvar d = new Date();\nvar dateNow = d.toLocaleDateString('pl-PL', options);\nd = new Date(startdate);\ndateFrom = d.toLocaleDateString('pl-PL', options);\nd = new Date(enddate);\ndateTo = d.toLocaleDateString('pl-PL', options);\n\nvar content_table_inactivity = \n\"<table><tbody><tr><td style=\\\"width: 25%;\\\"></td>\"+\n\"<td style=\\\"width: 50%;\\\">Something</td>\"+\n\"<td style=\\\"width: 50%;\\\">Something</td></tr></tbody></table>\";\n\nvar content_table_worktime = content_table_inactivity;\n\n\nvar contents = {\n CompanyName: CompanyName,\n CompanyLogoURL: CompanyLogoURL,\n machineName: selected_machine_name,\n dateNow: dateNow,\n dateFrom: dateFrom,\n dateTo: dateTo,\n content_table_inactivity: content_table_inactivity,\n content_table_worktime: content_table_worktime,\n content_var_prod_mean: content_var_prod_mean,\n content_var_prod_max: content_var_prod_max,\n content_var_prod_min: content_var_prod_min,\n content_var_prod_sum: content_var_prod_sum,\n content_var_inac_count: content_var_inac_count,\n content_var_inac_sum: content_var_inac_sum,\n content_var_inac_mean: content_var_inac_mean\n}\n\nreturn contents;","outputs":1,"noerr":0,"x":500,"y":2260,"wires":[["78005aa7.2aea84","8863f47.66d9308"]]},{"id":"78005aa7.2aea84","type":"debug","z":"74c70725.489d28","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":705,"y":2305,"wires":[]},{"id":"d3b19fb5.ccfc4","type":"debug","z":"74c70725.489d28","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":910,"y":2300,"wires":[]},{"id":"8863f47.66d9308","type":"template","z":"74c70725.489d28","name":"Raport_template1_main","field":"payload","fieldType":"msg","format":"html","syntax":"mustache","template":"<p><span style=\"color: #008080;\"> </span></p>\n<table style=\"height: 27px; margin-left: auto; margin-right: auto;\" border=\"1\" width=\"90%\">\n<tbody>\n<tr>\n<td style=\"width: 75%;\"><span style=\"color: #008080;\"><strong>Raport</strong></span></td>\n<td style=\"width: 25%;\"><span style=\"color: #008080;\"><strong><img style=\"display: block; margin-left: auto; margin-right: auto;\" src=\"{{CompanyLogoURL}}\" alt=\"{{CompanyName}}\" width=\"150\" height=\"33\" /></strong></span></td>\n</tr>\n</tbody>\n</table>\n<table style=\"height: 12px; width: 90%; margin-left: auto; margin-right: auto;\" border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 15%;\"><span style=\"color: #008080;\"><strong>Maszyna:</strong></span></td>\n<td style=\"width: 35%;\"><span style=\"color: #008080;\">{{machineName}}</span></td>\n<td style=\"width: 25%;\"><span style=\"color: #008080;\"><strong>OD:</strong> {{dateFrom}}</span></td>\n<td style=\"width: 25%;\"><span style=\"color: #008080;\"><strong>DO:</strong> {{dateTo}}</span></td>\n</tr>\n</tbody>\n</table>\n<table style=\"height: 12px; width: 90%; margin-left: auto; margin-right: auto;\" border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 10%;\"><span style=\"color: #008080;\"><strong>Firma:</strong></span></td>\n<td style=\"width: 90%;\"><span style=\"color: #008080;\">{{CompanyName}}</span></td>\n</tr>\n</tbody>\n</table>\n<table style=\"height: 26px; margin-left: auto; margin-right: auto;\" width=\"90%\">\n<tbody>\n<tr>\n<td style=\"width: 512.267px;\"><span style=\"color: #008080;\"><strong>Wydajność</strong></span></td>\n</tr>\n</tbody>\n</table>\n<table style=\"height: 243px; margin-left: auto; margin-right: auto;\" border=\"1\" width=\"90%\">\n<tbody>\n<tr style=\"height: 249px;\">\n<td style=\"width: 540.8px; height: 249px; text-align: center;\"><span style=\"color: #008080;\"> IMAGE_GRAPH HERE</span></td>\n</tr>\n<tr style=\"height: 33.6px;\">\n<td style=\"width: 540.8px; height: 33.6px;\">\n<table style=\"height: 15px;\" width=\"100%\">\n<tbody>\n<tr>\n<td style=\"width: 25%;\"><strong><span style=\"color: #008080;\">Średnia: </span></strong><span style=\"color: #008080;\">{{content_var_prod_mean}}</span></td>\n<td style=\"width: 25%;\"><strong><span style=\"color: #008080;\">MAX: </span></strong><span style=\"color: #008080;\">{{content_var_prod_max}}</span></td>\n<td style=\"width: 25%;\"><strong><span style=\"color: #008080;\">MIN: </span></strong><span style=\"color: #008080;\">{{content_var_prod_min}}</span></td>\n<td style=\"width: 25%;\"><strong><span style=\"color: #008080;\">SUMA: </span></strong><span style=\"color: #008080;\">{{content_var_prod_sum}}</span></td>\n</tr>\n</tbody>\n</table>\n</td>\n</tr>\n</tbody>\n</table>\n\n<br >\nExample try of my chart ;/\n<br />\n<html>\n\t\n\t\t<title>chart created with amCharts | amCharts</title>\n\t\t<meta name=\"description\" content=\"chart created using amCharts live editor\" />\n\t\t\n\t\t<!-- amCharts javascript sources -->\n\t\t<script type=\"text/javascript\" src=\"https://www.amcharts.com/lib/3/amcharts.js\"></script>\n\t\t<script type=\"text/javascript\" src=\"https://www.amcharts.com/lib/3/serial.js\"></script>\n\t\t\n\n\t\t<!-- amCharts javascript code -->\n\t\t<script type=\"text/javascript\">\n\t\t\tAmCharts.makeChart(\"chartdiv\",\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"serial\",\n\t\t\t\t\t\"categoryField\": \"category\",\n\t\t\t\t\t\"startDuration\": 1,\n\t\t\t\t\t\"categoryAxis\": {\n\t\t\t\t\t\t\"gridPosition\": \"start\"\n\t\t\t\t\t},\n\t\t\t\t\t\"trendLines\": [],\n\t\t\t\t\t\"graphs\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"balloonText\": \"[[title]] of [[category]]:[[value]]\",\n\t\t\t\t\t\t\t\"fillAlphas\": 1,\n\t\t\t\t\t\t\t\"id\": \"AmGraph-1\",\n\t\t\t\t\t\t\t\"title\": \"graph 1\",\n\t\t\t\t\t\t\t\"type\": \"column\",\n\t\t\t\t\t\t\t\"valueField\": \"column-1\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"balloonText\": \"[[title]] of [[category]]:[[value]]\",\n\t\t\t\t\t\t\t\"fillAlphas\": 1,\n\t\t\t\t\t\t\t\"id\": \"AmGraph-2\",\n\t\t\t\t\t\t\t\"title\": \"graph 2\",\n\t\t\t\t\t\t\t\"type\": \"column\",\n\t\t\t\t\t\t\t\"valueField\": \"column-2\"\n\t\t\t\t\t\t}\n\t\t\t\t\t],\n\t\t\t\t\t\"guides\": [],\n\t\t\t\t\t\"valueAxes\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"id\": \"ValueAxis-1\",\n\t\t\t\t\t\t\t\"title\": \"Axis title\"\n\t\t\t\t\t\t}\n\t\t\t\t\t],\n\t\t\t\t\t\"allLabels\": [],\n\t\t\t\t\t\"balloon\": {},\n\t\t\t\t\t\"legend\": {\n\t\t\t\t\t\t\"enabled\": true,\n\t\t\t\t\t\t\"useGraphSettings\": true\n\t\t\t\t\t},\n\t\t\t\t\t\"titles\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"id\": \"Title-1\",\n\t\t\t\t\t\t\t\"size\": 15,\n\t\t\t\t\t\t\t\"text\": \"Chart Title\"\n\t\t\t\t\t\t}\n\t\t\t\t\t],\n\t\t\t\t\t\"dataProvider\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"category\": \"category 1\",\n\t\t\t\t\t\t\t\"column-1\": 8,\n\t\t\t\t\t\t\t\"column-2\": 5\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"category\": \"category 2\",\n\t\t\t\t\t\t\t\"column-1\": 6,\n\t\t\t\t\t\t\t\"column-2\": 7\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"category\": \"category 3\",\n\t\t\t\t\t\t\t\"column-1\": 2,\n\t\t\t\t\t\t\t\"column-2\": 3\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t);\n\t\t</script>\n\t\n\t\n\t\t<div id=\"chartdiv\" style=\"width: 100%; height: 400px; background-color: #FFFFFF;\" ></div>\n\t\n</html>\n","output":"str","x":710,"y":2260,"wires":[["d3b19fb5.ccfc4","1a051022.28a83"]]},{"id":"1a051022.28a83","type":"function","z":"74c70725.489d28","name":"path","func":"\nvar main_path = \"C:/AAAtemp/\";\nvar name = \"Raport.pdf\";\n\nmsg.filename = main_path + name;\nreturn msg;","outputs":1,"noerr":0,"x":950,"y":2260,"wires":[["cd687ea2.91d25"]]},{"id":"33eca129.f5abce","type":"comment","z":"74c70725.489d28","name":"edit your path","info":"","x":950,"y":2220,"wires":[]}]