Chart Widget¶
Chart binds the built-in ratatui::widgets::Chart API for cartesian plots.
Types¶
ChartDatasetAxisGraphType(Scatter,Line,Bar)MarkerLegendPosition
Multi-Dataset Example¶
from pyratatui import Axis, Chart, Dataset, GraphType, Marker
line_points = [(0.0, 1.0), (1.0, 3.0), (2.0, 2.0), (3.0, 5.0)]
scatter_points = [(0.5, 1.4), (1.5, 2.3), (2.5, 3.1)]
bar_points = [(0.0, 1.0), (1.0, 2.2), (2.0, 1.8), (3.0, 2.9)]
datasets = [
Dataset(line_points).name("Line").graph_type(GraphType.Line).marker(Marker.Braille),
Dataset(scatter_points).name("Scatter").graph_type(GraphType.Scatter).marker(Marker.Dot),
Dataset(bar_points).name("Bars").graph_type(GraphType.Bar).marker(Marker.Bar),
]
chart = (
Chart(datasets)
.x_axis(Axis().title("X").bounds(0.0, 3.0).labels(["0", "1.5", "3"]))
.y_axis(Axis().title("Y").bounds(0.0, 6.0).labels(["0", "3", "6"]))
)
Render:
Axis Notes¶
Axis.bounds(min, max)defines visible range.Axis.labels([...])sets tick labels.Axis.labels_alignment("left" | "center" | "right")controls label alignment.
Legend¶
Use chart.legend_position(...) with:
LegendPosition.TopLegendPosition.TopRightLegendPosition.TopLeftLegendPosition.LeftLegendPosition.RightLegendPosition.BottomLegendPosition.BottomRightLegendPosition.BottomLeft
Set None to hide the legend: