Server-side chart rendering with JxBrowser

This project demonstrates how to render and export HTML/CSS/JS charts on the server side using JxBrowser.

Chart rendering

Problem 

Business people often want to automate their reporting. The resulting files may include a variety of data, including charts over different slices of the app’s domain. In terms of development, it is pretty costly to implement and support such a chart rendering on the server-side, in the JVM world.

At the same time, the modern HTML/CSS/JS tech stack provides a lot of means to build any charts. Being executed in a browser, such a code renders the charts the same for every end-user. It would be nice to use this approach on a JVM server/desktop application and write an automated solution to export images with no need for human actions, such as making screenshots.

Solution 

This example demonstrates how to tackle these challenges with JxBrowser. The showcased application is a web server that utilizes the JxBrowser API to render an arbitrary web page, and then export it to an image. The resulting images are exactly the same as if they are rendered by a plain desktop Chromium browser.

With such an approach, the application renders the HTML/CSS/JS charts directly on the server side, upon a programmatic request. Once built and run, this solution requires no human interaction or intervention. It can be hosted on a dedicated server or a Cloud VM, rendering and sharing charts upon requests, such as a cron job or a REST API call from another program.

To sum up, here is a short list of benefits:

  1. Full automation of rendering.
  2. Ability to use anything the web world provides, including excellent libraries like Chart.js, Bootstrap or Material typography, with a Java/Kotlin application.
  3. Re-use the same chart-drawing code on the web server and the web client, e.g., to generate a preview. The outcome is identical.

Licensing and reuse

The code of this project is provided under the MIT license. We encourage our clients to treat it as a source of inspiration, or even by directly using its parts in their applications.