BarChart

Display

Renders a horizontal bar chart with optional label, colors and value display.

@using RazorConsole.Components
@using System.Globalization
@using Spectre.Console

<RazorConsole.Components.BarChart BarChartItems="@SalesData"
          Label="Revenue 2025"
          Width="80"
          ShowValues="true"
          LabelAlignment="Justify.Center" />

@code {
   private List<IBarChartItem> SalesData => new()
   {
        new BarChartItem("Jan", 65.2, Color.FromHex("29B8DB")),
        new BarChartItem("Feb", 78.9, Color.FromHex("0DBC79")),
        new BarChartItem("Mar", 91.5, Color.FromHex("F5F543"))
   };
}

Parameters

10
NameTypeDefaultDescription
Appearance
LabelBackgroundColor?Background color of the chart label. Default is Plain background (transparent).
LabelForegroundColor?Foreground (text) color of the chart label. Default is Plain foreground.
Widthint?Width of the bar chart in characters. If null , uses available console width.
Common
Labelstring?Label (title) displayed above the bar chart.
MaxValuedouble?Fixed maximum value for scaling bars. When set, bars scale relative to this value instead of the largest data point. Example: MaxValue = 100 creates a progress chart (0–100%).
ShowValuesboolWhether numeric values should be displayed next to each bar. Default is false .
Other
BarChartItemsList<IBarChartItem>Renders a bar chart using Spectre.Console's BarChart renderable.
CultureCultureInfo?CultureInfo to use when rendering values. Default is CurrentCulture.
LabelAlignmentJustify?Alignment of the chart label. Options: Left, Center, Right.
LabelDecorationDecoration?Text decoration for the chart label (bold, italic, underline, etc.). Default is None.

API