I've been pushing the boundaries of what's possible with automated reporting in n8n and wanted to share a recent breakthrough.
We all know that generating basic HTML reports is straightforward, but creating truly dynamic, professional-grade visualizations can be a challenge.
My goal was to create a fully interactive D3.js dashboard, embed it in a report, and have it render perfectly in both a browser and a generated PDF.
The catch? I wanted to do it without coding the D3.js visualization manually.
In case you are not familiar with D3.js, it is a free, open-source JavaScript library that enables developers to create dynamic, interactive data visualizations in web browsers using web standards like HTML, SVG, and CSS.
D3 stands for "Data-Driven Documents" and allows data to be bound to DOM elements, making it possible to manipulate documents based on the underlying data.
Unlike template-based chart libraries, D3 provides low-level helper functions to select elements, bind data, and generate custom visualizations with maximum flexibility.
D3 empowers developers to build a wide variety of visualizations, including charts, graphs, maps, and more, with responsive interactivity and animation support.
After some of trial and error, I've perfected a workflow that uses a n8n workflow as a "D3.js coder on demand."
The final result running inside a report is shown on the video.
I'm considering making a detailed video tutorial on the entire workflow, which would cover:
- Data Shaping: Using a Code node to transform a messy API response into a clean JSON array perfect for D3. (I'll share the AI prompt used to generate this transformation script).
- The "Component Prompt": The exact prompt I used to get an LLM to write the complete, minified, and self-contained HTML/CSS/D3.js component with responsive viewBox SVGs.
- Dynamic Injection: The final "Set" node expression for combining a master CSS template, the main report body, and the dynamically generated dashboard component.
- PDF Generation: How the responsive viewBox trick finally solves the "truncated chart in PDF" problem.
Would a tutorial on this topic be useful for the community?
I think it's a powerful way to elevate the kinds of reports we can build automatically.
Curious to hear your thoughts!