Databricks AI/BI dashboards ship with a solid set of visualization types. But every so often you want something the point-and-click widgets can't quite do.
That's what custom visualizations (currently Public Preview) are for. You describe the chart in a Vega-Lite spec (a block of JSON), and that spec controls every part of the chart in one place. Since your custom viz reads your Unity Catalog (UC) data through the dashboards dataset, you get all the governance of UC you’ve come to expect on Databricks.
To show it off, we'll build a custom Pareto chart of manufacturing defects. It has the usual bars and cumulative line, but the focus is on what a built-in combo widget in AI/BI Dashboards can’t do in the UI today:
The final custom visualization we will create below. Feel free to follow along in Databricks Free Edition!
Vega-Lite Overview
Vega-Lite is a JSON grammar for charts. Instead of writing drawing code, you describe the chart it renders. To summarize what’s needed for this post, we draw attention to the following key ideas:
Connect your data to the custom visualization
Create the Custom Pareto Chart
Step 1: Create the dashboard
Step 2: Create the data
|
A custom viz draws what's in your dataset to start, so for a Pareto chart the data summary is where the majority of work happens.
Unlike a plain bar chart, the summary data in a Pareto is order-dependent. It requires:
The columns that matter for the chart
Step 3: Build the custom visualization
In the dashboard UI
With your widget set, now paste the spec below into the Vega-Lite Specification editor.
|
In the era of AI Agents and LLMs, you should expect to not have to write this by hand and the same is true on Databricks. This was generated with Genie Code and refined from there, so treat the JSON as something to read and modify as you would with any piece of code generated by AI.
Spec overview
We will highlight a few main areas of interest in this task:
Data binding and sorting
Layering builds the visualization
Independent y-axes
Transforms add logic
Dynamic annotations
Step 3: Polish with Genie Code (Output can vary)
You don't have to manually write or update the JSON. Genie Code can create or edit the spec for you in natural language throughout this entire process.
Use Genie Code to update the current visualization.
|
Genie applies the edits and you keep iterating from there!
Building it with AI (Genie Code here): what to watch for
AI output varies. If you build this from scratch or update with AI, keep an eye on a few things:
Your turn! Can you make it better?
The Vega-Lite spec above is one solution, but it can be improved. See what you can come up with. Try it in Databricks Free Edition!
Made it better? Share your spec and a screenshot in the comments. The best ideas help everyone learn new techniques for building custom visualizations.
Learn more
Special thanks to Maggie Li, Matthew McCoy and Marcelino Mayorga.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.