BarChart
DisplayRenders 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| Name | Type | Default | Description |
|---|---|---|---|
Appearance | |||
LabelBackground | Color? | — | Background color of the chart label. Default is Plain background (transparent). |
LabelForeground | Color? | — | Foreground (text) color of the chart label. Default is Plain foreground. |
Width | int? | — | Width of the bar chart in characters. If null , uses available console width. |
Common | |||
Label | string? | — | Label (title) displayed above the bar chart. |
MaxValue | double? | — | 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%). |
ShowValues | bool | — | Whether numeric values should be displayed next to each bar. Default is false . |
Other | |||
BarChartItems | List<IBarChartItem> | — | Renders a bar chart using Spectre.Console's BarChart renderable. |
Culture | CultureInfo? | — | CultureInfo to use when rendering values. Default is CurrentCulture. |
LabelAlignment | Justify? | — | Alignment of the chart label. Options: Left, Center, Right. |
LabelDecoration | Decoration? | — | Text decoration for the chart label (bold, italic, underline, etc.). Default is None. |