renderChart<X extends ChartX>(spec: ChartSpec<X>): stringrenderChart — 6.0.0
Signature
Executable examples
Structured chart
renderChart({
width: 42,
height: 10,
series: [
{ id: 'latency', data: [['Mon', 42], ['Tue', 68], ['Wed', 51]] },
{ id: 'errors', data: [['Mon', 2], ['Tue', 7], ['Wed', 3]], yAxis: 'secondary' },
],
xAxis: { scale: 'band' },
secondaryYAxis: { domain: [0, 10] },
annotations: [{ id: 'warning', type: 'span', axis: 'y', from: 60, to: 80 }],
legend: { position: 'bottom', series: true },
});
▲ ▲
68┤░░░░░░░░░░░░░░░░░░░░┏━━━━━━━━━━━━┓░░░░░░░░│
│░░░░░░░░░░░░░░░░░░░░┃░░░░░░░░░░░░┃░░░░░░░░│
│░░░░░░░░░░░░░░░░░░░░┃░░░░░░░░░░░░┃░░░░░░░░│
│░░░░░░░░░░░░░░░░░░░░┏━━━━━━━━━━━━┓░░░░░░░░├7
│ ┃ ┃ │
│ ┃ ┃ │
51┤ ┃ ┗━ ├3
│ ━━━━━━━━━━━━━┛ ├2
│ ┃ │
42┤ ━━━━━━━━━━━━━┛ │
└───────┬─────────────┬────────────┬───────┘
Mon Tue Wed
█ latency
█ errors
ChartSpec
Complete structured chart specification.
type ChartSpec = {
/** Structured series collection. May be empty; explicit axis domains can define an empty frame. */
series: readonly ChartSeries<X>[];
/** Fixed plot width or `auto` for active terminal columns. Defaults to 60. */
width?: ChartWidth;
/** Plot height in terminal rows. Defaults to 15 unless derived. */
height?: number;
/** Desired physical width-to-height ratio used when height is derived. */
aspectRatio?: number;
/** Title rendered above the chart. */
title?: string;
/** ANSI color applied to the title. */
titleColor?: Color;
/** Line behavior outside explicit domains. Defaults to `discard`. */
overflow?: Overflow;
/** Plot-cell backend. Defaults to `ascii`. */
renderer?: Renderer;
/** Native X-axis configuration. */
xAxis?: XAxis<X>;
/** Primary numeric Y-axis configuration. */
yAxis?: YAxis;
/** Independently scaled right-side Y-axis configuration. */
secondaryYAxis?: YAxis;
/** Legend placement, entity selection, and ANSI color. */
legend?: ChartLegend;
/** Explicit numeric X/Y axis intersection. */
axisCenter?: MaybePoint;
/** Named point overlays rendered on the primary Y-axis. */
points?: readonly ChartOverlayPoint<X>[];
/** Named reference lines rendered on the primary Y-axis. */
thresholds?: readonly ChartThreshold<X>[];
/** Data-coordinate spans, text, arrows, and error bars. */
annotations?: readonly ChartAnnotation<X>[];
/** Per-call glyph overrides. */
symbols?: Symbols;
/** ANSI color applied to the configured border glyph. */
borderColor?: Color;
/** ANSI color applied to background glyphs. */
backgroundColor?: Color;
/** Logs out-of-bounds drawing attempts for diagnostics. */
debugMode?: boolean;
/** Shared arrangement for multi-series bars. Defaults to `overlap`. */
barLayout?: BarLayout;
/** Enables bar endpoint labels or configures their text and color. */
valueLabels?: ChartValueLabels<X>;
};series
Structured series collection. May be empty; explicit axis domains can define an empty frame.
Related executable examples: Structured chart
width
Fixed plot width or auto for active terminal columns. Defaults to 60.
Related executable examples: Structured chart
height
Plot height in terminal rows. Defaults to 15 unless derived.
Related executable examples: Structured chart
aspectRatio
Desired physical width-to-height ratio used when height is derived.
Related executable examples: Structured chart
titleColor
ANSI color applied to the title.
Related executable examples: Structured chart
overflow
Line behavior outside explicit domains. Defaults to discard.
Related executable examples: Structured chart
renderer
Plot-cell backend. Defaults to ascii.
Related executable examples: Structured chart
yAxis
Primary numeric Y-axis configuration.
Related executable examples: Structured chart
secondaryYAxis
Independently scaled right-side Y-axis configuration.
Related executable examples: Structured chart
legend
Legend placement, entity selection, and ANSI color.
Related executable examples: Structured chart
axisCenter
Explicit numeric X/Y axis intersection.
Related executable examples: Structured chart
points
Named point overlays rendered on the primary Y-axis.
Related executable examples: Structured chart
thresholds
Named reference lines rendered on the primary Y-axis.
Related executable examples: Structured chart
annotations
Data-coordinate spans, text, arrows, and error bars.
Related executable examples: Structured chart
borderColor
ANSI color applied to the configured border glyph.
Related executable examples: Structured chart
backgroundColor
ANSI color applied to background glyphs.
Related executable examples: Structured chart
debugMode
Logs out-of-bounds drawing attempts for diagnostics.
Related executable examples: Structured chart
barLayout
Shared arrangement for multi-series bars. Defaults to overlap.
Related executable examples: Structured chart
valueLabels
Enables bar endpoint labels or configures their text and color.
Related executable examples: Structured chart
ChartSeries
One independently styled series in a structured chart.
type ChartSeries = {
/** Unique series identifier used by legends and callback context. */
id: string;
/** Human-readable series label. Defaults to `id`. */
name?: string;
/** Native-X/numeric-Y values; `null` creates a continuity gap. */
data: readonly ChartDatum<X>[];
/** Series rendering primitive. Defaults to `line`. */
mode?: GraphMode;
/** Line-segment interpolation. Defaults to `step`. */
interpolation?: Interpolation;
/** Static ANSI series color. */
color?: Color;
/** Dynamic per-cell series-color strategy. */
coloring?: Coloring;
/** Fills the region between a line and the X-axis baseline. */
fillArea?: boolean;
/** Custom glyph callback for occupied series cells. */
lineFormatter?: (args: LineFormatterArgs) => CustomSymbol | CustomSymbol[];
/** Y-axis assignment. Defaults to `primary`. */
yAxis?: 'primary' | 'secondary';
};id
Unique series identifier used by legends and callback context.
Related executable examples: Structured chart
name
Human-readable series label. Defaults to id.
Related executable examples: Structured chart
data
Native-X/numeric-Y values; null creates a continuity gap.
Related executable examples: Structured chart
mode
Series rendering primitive. Defaults to line.
Related executable examples: Structured chart
interpolation
Line-segment interpolation. Defaults to step.
Related executable examples: Structured chart
coloring
Dynamic per-cell series-color strategy.
Related executable examples: Structured chart
fillArea
Fills the region between a line and the X-axis baseline.
Related executable examples: Structured chart
lineFormatter
Custom glyph callback for occupied series cells.
Related executable examples: Structured chart
yAxis
Y-axis assignment. Defaults to primary.
Related executable examples: Structured chart
ChartLegend
Legend configuration and optional entity selection by id.
type ChartLegend = {
/** Placement relative to the plot. */
position: LegendPosition;
/** `true` shows all series; an ID array selects and orders entries. */
series?: boolean | readonly string[];
/** `true` shows all points; an ID array selects and orders entries. */
points?: boolean | readonly string[];
/** `true` shows all thresholds; an ID array selects and orders entries. */
thresholds?: boolean | readonly string[];
/** ANSI color applied to legend labels. */
color?: Color;
};position
Placement relative to the plot.
Related executable examples: Structured chart
series
true shows all series; an ID array selects and orders entries.
Related executable examples: Structured chart
points
true shows all points; an ID array selects and orders entries.
Related executable examples: Structured chart
thresholds
true shows all thresholds; an ID array selects and orders entries.
Related executable examples: Structured chart
ChartOverlayPoint
Named overlay point for a structured chart.
type ChartOverlayPoint = Omit<GraphPoint, 'x'> & {
/** Unique point identifier used by legends. */
id: string;
/** Human-readable point label. Defaults to `id`. */
name?: string;
/** Native X coordinate. */
x: X;
};color
ANSI color applied to the point glyph.
Related executable examples: Structured chart
id
Unique point identifier used by legends.
Related executable examples: Structured chart
name
Human-readable point label. Defaults to id.
Related executable examples: Structured chart
ChartThreshold
Named threshold for a structured chart.
type ChartThreshold = Omit<Threshold, 'x'> & {
/** Unique threshold identifier used by legends. */
id: string;
/** Human-readable threshold label. Defaults to `id`. */
name?: string;
/** Optional native X coordinate for a vertical reference line. */
x?: X;
};y
Y coordinate for a horizontal reference line.
Related executable examples: Structured chart
color
ANSI color applied to the reference line.
Related executable examples: Structured chart
id
Unique threshold identifier used by legends.
Related executable examples: Structured chart
name
Human-readable threshold label. Defaults to id.
Related executable examples: Structured chart
x
Optional native X coordinate for a vertical reference line.
Related executable examples: Structured chart
XAxis
Structured X-axis configuration.
type XAxis = {
/** Scale kind. Defaults to the kind inferred from X values. */
scale?: XScale;
/** Explicit category order or continuous scale extent. */
domain?: XAxisDomain<X>;
/** Exact native tick values or an exact tick count of at least two. */
ticks?: number | readonly X[];
/** Axis label rendered outside tick labels. */
label?: string;
/** Formatter called with native X values. */
formatter?: AxisFormatter<X>;
/** Hides the axis line, ticks, labels, and axis label. */
hidden?: boolean;
/** Hides tick markers and labels while retaining the axis line. */
hideTicks?: boolean;
/** Handling for labels that do not fit the available width. */
labelCollision?: LabelCollisionPolicy;
/** ANSI color applied to the axis line, ticks, tick labels, and label. */
color?: Color;
};scale
Scale kind. Defaults to the kind inferred from X values.
Related executable examples: Structured chart
domain
Explicit category order or continuous scale extent.
Related executable examples: Structured chart
ticks
Exact native tick values or an exact tick count of at least two.
Related executable examples: Structured chart
label
Axis label rendered outside tick labels.
Related executable examples: Structured chart
formatter
Formatter called with native X values.
Related executable examples: Structured chart
hidden
Hides the axis line, ticks, labels, and axis label.
Related executable examples: Structured chart
hideTicks
Hides tick markers and labels while retaining the axis line.
Related executable examples: Structured chart
labelCollision
Handling for labels that do not fit the available width.
Related executable examples: Structured chart
color
ANSI color applied to the axis line, ticks, tick labels, and label.
Related executable examples: Structured chart
YAxis
Numeric Y-axis configuration.
type YAxis = {
/** Explicit numeric extent as `[minimum, maximum]`. */
domain?: readonly [number, number];
/** Exact numeric tick values or an exact tick count of at least two. */
ticks?: number | readonly number[];
/** Axis label rendered outside tick labels. */
label?: string;
/** Formatter called for each numeric Y-axis tick. */
formatter?: Formatter;
/** Hides the axis line, ticks, labels, and axis label. */
hidden?: boolean;
/** Hides tick markers and labels while retaining the axis line. */
hideTicks?: boolean;
/** Reserves enough width for complete Y-axis tick labels. */
showTickLabel?: boolean;
/** ANSI color applied to the axis line, ticks, tick labels, and label. */
color?: Color;
};domain
Explicit numeric extent as [minimum, maximum].
Related executable examples: Structured chart
ticks
Exact numeric tick values or an exact tick count of at least two.
Related executable examples: Structured chart
label
Axis label rendered outside tick labels.
Related executable examples: Structured chart
formatter
Formatter called for each numeric Y-axis tick.
Related executable examples: Structured chart
hidden
Hides the axis line, ticks, labels, and axis label.
Related executable examples: Structured chart
hideTicks
Hides tick markers and labels while retaining the axis line.
Related executable examples: Structured chart
showTickLabel
Reserves enough width for complete Y-axis tick labels.
Related executable examples: Structured chart
color
ANSI color applied to the axis line, ticks, tick labels, and label.
Related executable examples: Structured chart
Coloring
Dynamic per-cell series-color strategy.
type Coloring = {
/** Selects callback-based colors. */
type: 'conditional';
/** Returns a color or `undefined` to use the static series fallback. */
getColor: (context: ColorContext) => Color | undefined;
} | {
/** Selects equal-band palette coloring. */
type: 'gradient';
/** Data-space axis used to select a palette band. */
by: 'x' | 'y';
/** Nonempty ordered ANSI color palette. */
colors: readonly Color[];
/** Optional finite palette extent. Defaults to the resolved chart domain. */
domain?: readonly [number, number];
};type
Selects callback-based colors.
Related executable examples: Structured chart
getColor
Returns a color or undefined to use the static series fallback.
Related executable examples: Structured chart
by
Data-space axis used to select a palette band.
Related executable examples: Structured chart
colors
Nonempty ordered ANSI color palette.
Related executable examples: Structured chart
domain
Optional finite palette extent. Defaults to the resolved chart domain.
Related executable examples: Structured chart
ChartValueLabels
Enables bar endpoint labels or configures their text and ANSI color.
type ChartValueLabels = boolean | {
/** Formats the rendered value; normalized layouts receive a percentage. */
formatter?: ValueLabelFormatter<X>;
/** ANSI color applied to every value label. */
color?: Color;
};formatter
Formats the rendered value; normalized layouts receive a percentage.
Related executable examples: Structured chart
color
ANSI color applied to every value label.
Related executable examples: Structured chart
ChartSpanAnnotation
Reference region spanning an inclusive X or Y interval.
type ChartSpanAnnotation = ChartAnnotationBase & (Readonly<{
/** Span annotation discriminator. */
type: 'span';
/** Fills an X-axis interval across the complete plot height. */
axis: 'x';
/** Inclusive native interval start. */
from: X;
/** Inclusive native interval end. */
to: X;
/** One-column fill glyph. */
symbol?: string;
}> | Readonly<{
/** Span annotation discriminator. */
type: 'span';
/** Fills a Y-axis interval across the complete plot width. */
axis: 'y';
/** Inclusive numeric interval start. */
from: number;
/** Inclusive numeric interval end. */
to: number;
/** One-column fill glyph. */
symbol?: string;
}>);color
ANSI color applied to the complete annotation.
Related executable examples: Structured chart
axis
Fills an X-axis interval across the complete plot height.
Related executable examples: Structured chart
ChartTextAnnotation
Text anchored at one data coordinate.
type ChartTextAnnotation = ChartAnnotationBase & Readonly<{
/** Text annotation discriminator. */
type: 'text';
/** Native X anchor. */
x: X;
/** Numeric Y anchor. */
y: number;
/** Display-safe terminal text. */
text: string;
/** Horizontal placement relative to the anchor. Defaults to `right`. */
align?: 'left' | 'center' | 'right';
}>;color
ANSI color applied to the complete annotation.
Related executable examples: Structured chart
align
Horizontal placement relative to the anchor. Defaults to right.
Related executable examples: Structured chart
ChartArrowAnnotation
Arrow connecting two data coordinates.
type ChartArrowAnnotation = ChartAnnotationBase & Readonly<{
/** Arrow annotation discriminator. */
type: 'arrow';
/** Native-X/numeric-Y path start. */
from: readonly [x: X, y: number];
/** Native-X/numeric-Y path end and arrowhead position. */
to: readonly [x: X, y: number];
/** One-column path glyph. */
lineSymbol?: string;
}>;color
ANSI color applied to the complete annotation.
Related executable examples: Structured chart
from
Native-X/numeric-Y path start.
Related executable examples: Structured chart
to
Native-X/numeric-Y path end and arrowhead position.
Related executable examples: Structured chart
ChartErrorBarAnnotation
Error whiskers centered on one data coordinate.
type ChartErrorBarAnnotation = ChartAnnotationBase & Readonly<{
/** Error-bar annotation discriminator. */
type: 'errorBar';
/** Native X center. */
x: X;
/** Numeric Y center. */
y: number;
/** Symmetric or asymmetric Y-axis error magnitude. */
yError?: ChartErrorMagnitude;
}> & ([X] extends [string] ? Readonly<{
xError?: never;
}> : Readonly<{
/** Symmetric or asymmetric X-axis error magnitude. */
xError?: ChartErrorMagnitude;
}>);color
ANSI color applied to the complete annotation.
Related executable examples: Structured chart
type
Error-bar annotation discriminator.
Related executable examples: Structured chart
yError
Symmetric or asymmetric Y-axis error magnitude.
Related executable examples: Structured chart