Many dashboards eventually answer the same questions:
A dumbbell chart answers these questions at a glance.
Databricks AI/BI dashboards do not have a built-in dumbbell chart widget, so you will build one with a custom visualization (currently Public Preview) widget. Custom visualizations use the Vega-Lite library to render charts from a JSON specification. The visualization reads directly from your AI/BI dashboard dataset, so you can go beyond the built-in chart types while continuing to work with your governed data in Databricks.
We will consider the following scenario: You've been asked to report Regional Sales Performance vs. Targets. You decide to use a dumbbell chart to clearly show the gap between actual sales and targets.
You'll build the following visualization in an AI/BI dashboard:
Create the Custom Dumbbell Chart
Feel free to follow along in Databricks Free Edition.
Step 1: Create the dashboard
Step 2: Create the data
We start from a small, pre-aggregated dataset with one row per region.
To keep this post simple, we build that data inline with a VALUES clause instead of creating a detailed source table and aggregating it. In a real project, you would aggregate a detailed table or pull from an existing aggregated table.
|
| region | actual | target | gap | status |
|---|---|---|---|---|
| West | 92000 | 70000 | 22000 | At or above target |
| Southeast | 73000 | 81000 | -8000 | Below target |
| Midwest | 68000 | 64000 | 4000 | At or above target |
| Northeast | 60000 | 66000 | -6000 | Below target |
| Pacific | 38000 | 75000 | -37000 | Below target |
| Southwest | 47000 | 52000 | -5000 | Below target |
| Mountain | 51000 | 48000 | 3000 | At or above target |
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:
|
You do not have to write a spec like this by hand. This one was generated and refined with Genie Code.
Step 4: Polish with Genie Code
As mentioned earlier, you do not have to write or update this JSON by hand. Genie Code can generate a first draft or refine an existing spec in natural language.
For example, for our final clean up let's use Genie Code.
Select the Genie Code icon, select your custom viz, and describe the changes that you want (output can vary):
|
See it update dynamically with new data
Here is where the dynamic design pays off.
Every channel keys off a column, sorted by gap, colored by status, labeled from gap, so new data just flows in.
|
The two new regions drop into the right sorted position by their gap, connectors colored by status, dots styled the same, and gap labels formatted, all with no change to the spec.
Build it once, and it stays correct as the source data is updated.
Your turn! Can you make it better?
The spec above is one solution, and there is plenty of room to improve it. Try it in Databricks Free Edition and see what you can do. 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
New to AI/BI Dashboards? The AI/BI for Data Analysts course on Databricks Academy covers building interactive dashboards, creating visualizations, using Genie Code for AI development, publishing, scheduling, and more.
Special thanks to Louis Frolio, Maggie Li, and Matthew McCoy for technical review.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.