I want to create Google Charts at server-end. I found some plugins like - GWT Tutorial, but I did not find it helpful because we need client-side interaction here. I need something using which I can create charts at server end so that I can store these charts images without requiring user to interact. I also found one more plugin - Charts4j, but I did not find any helpful examples or tutorial for this plugin.
Update
-
Using Thymeleaf
, I was able to load the HTML file to backend and was able to convert the HTML as PDF using HTMLToPDF plugin. The HTML is working beautifully fine. The PDF is getting generated. Now only issue left is that the javascript from HTML is not getting evaluated. Any solution for this?
Another Update
-
When I find a solution I find another obstacle. I was able to execute the script using ScripEngine, but ScriptEngine did not find document
. Then I used Java Jsoup's Document, sent the object to ScriptEngine, but again Jsoup's Document has different methods than Javascript's document.
I found a solution. I solved my issue using Thymeleaf
, Selenium
and IText HTML2PDF
. I followed given steps -
I added below dependencies to my POM -
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.0.3</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>html2pdf</artifactId>
<version>4.0.4</version>
</dependency>
Then, I resolved my HTML template containing javascript using ThymeleafResolver -
public ServletContextTemplateResolver templateResolver() {
ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
templateResolver.setPrefix("/<My folder name in resources>/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode("HTML");
return templateResolver;
}
public SpringTemplateEngine templateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver());
templateEngine.setTemplateEngineMessageSource(messageSource());
return templateEngine;
}
And in my code I used -
Context ctx = new Context();
String html = templateEngine.process(<My HTML file name>, ctx);
This resolved my HTML. Now, about javascript, I referred this - Evaludate JS, and my issue was resolved.
Thank you.