First chart

This tutorial walks through the fastest path from install to useful output.

Install

pip install textcharts

Render a basic bar chart

from textcharts import BarChart, BarData

data = [
    BarData(label="Fiction", value=18.4, is_best=True),
    BarData(label="Children", value=14.2),
    BarData(label="Comics", value=9.8, is_worst=True),
]

chart = BarChart(
    data=data,
    title="April Bookstore Revenue",
    metric_label="k USD",
)

print(chart.render())

What to expect

  • Labels are aligned and sorted for readability.

  • Best and worst values can be highlighted through the data model.

  • Unicode and color are enabled by default when the terminal supports them.

Use shared chart options

All chart types accept textcharts.ChartOptions.

from textcharts import BarChart, BarData, ChartOptions

options = ChartOptions(
    width=72,
    use_color=False,
    use_unicode=False,
)

chart = BarChart(
    data=[BarData(label="Saturday Tickets", value=412)],
    title="Festival Check-ins",
    options=options,
)

print(chart.render())

Build a chart from structured data

Most charts have a dedicated data model:

  • textcharts.BarData

  • textcharts.LinePoint

  • textcharts.ScatterPoint

  • textcharts.SpeedupData

  • textcharts.SummaryStats

Use those models directly. Convenience factory helpers are also available for one-shot chart creation — see Factory helpers.

Next steps