When to Use
- Financial statements: Show revenue breakdown to net income
- Budget variance: Track planned vs actual spending across categories
- Inventory changes: Visualize additions and withdrawals over time
- Performance attribution: Break down total performance into contributing factors
- Cumulative impact: Display how components sum to a final result
Basic Example
Bar Types
Delta Bars
with_delta(label: impl Into<String>, value: f64)
Add a floating delta bar. The bar spans from the current running total to current + value. Positive values are colored green; negative values red.
Total Bars
with_total(label: impl Into<String>)
Add a summary bar that spans from zero to the current running total. Rendered in color_total (default "steelblue"). Place after delta bars to show a subtotal or at the end for the final result.
Difference Bars
with_difference(label: impl Into<String>, from: f64, to: f64)
Add a standalone comparison bar anchored at explicit y-values. The bar spans [from, to] and is green when to > from, red when to < from. It does not affect the running total — purely illustrative.
Key Methods
with_bar_width(width: f64)
Set bar width as a fraction of the category slot (default 0.6).
with_color_positive(color: impl Into<String>)
Set color for positive delta bars (default "rgb(68,170,68)" — green).
with_color_negative(color: impl Into<String>)
Set color for negative delta bars (default "rgb(204,68,68)" — red).
with_color_total(color: impl Into<String>)
Set color for total/subtotal bars (default "steelblue").
with_connectors()
Draw dashed connector lines between the top (or bottom) of consecutive bars. Helps trace the running total across wide charts.
with_values()
Print numeric values as text labels on each bar. Delta bars show their value; total bars show the accumulated total; difference bars show to - from.
with_legend(label: impl Into<String>)
Attach a legend label to the waterfall chart.
Examples
Income Statement Breakdown
Budget Variance
Comparison with Reference
See Also
- BarPlot — For simple categorical bar charts
- StackedBarPlot — For cumulative bars without floating