BarChartWidget
BarChartWidget is a stateless, theme-aware vertical bar chart renderer built on Ratatui's BarChart. It is paint-only: it does not take focus, handle events, or own chart data.
There is no dedicated bar chart demo. The landing page renders a chart tile with BarChartWidget.
Basic Usage
rust
use ratatui::widgets::Bar;
use ratcn::BarChartWidget;
let bars = vec![
Bar::default().label("Jan".into()).value(12),
Bar::default().label("Feb".into()).value(18),
Bar::default().label("Mar".into()).value(9),
];
frame.render_widget(
BarChartWidget::new(bars)
.themed(&theme)
.max_value(20)
.bar_width(3)
.bar_gap(1),
area,
);BarChartWidget API
| Method | Description |
|---|---|
BarChartWidget::new(bars) | Creates a paint-only vertical bar chart from Bar values. |
.themed(&theme) | Applies theme-derived foreground, background, bar, value, and label colors. |
.style(BarChartStyle) | Uses an explicit style instead of a theme-derived one. |
.max_value(value) | Sets the maximum chart value. |
.max(value) | Alias for .max_value(value). |
.show_values(bool) | Shows or hides value labels. Defaults to true. |
.bar_width(width) | Sets the width of each bar. Defaults to 3. |
.bar_gap(gap) | Sets the gap between bars. Defaults to 1. |
Events
BarChartWidget handles no events. Render it directly with frame.render_widget(...).
Styling
Use .themed(&theme) for normal app rendering. Use .style(BarChartStyle) when you need explicit colors for a custom chart surface.