mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-11-04 10:35:27 +08:00 
			
		
		
		
	
				
					committed by
					
						
						Patrik Svensson
					
				
			
			
				
	
			
			
			
						parent
						
							1cf30f62fc
						
					
				
				
					commit
					7dccb310f3
				
			
							
								
								
									
										
											BIN
										
									
								
								docs/input/assets/images/barchart.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								docs/input/assets/images/barchart.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 3.5 KiB  | 
							
								
								
									
										75
									
								
								docs/input/widgets/barchart.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								docs/input/widgets/barchart.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,75 @@
 | 
			
		||||
Title: Bar Chart
 | 
			
		||||
Order: 1
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
Use `BarChart` to render bar charts to the console.
 | 
			
		||||
 | 
			
		||||
<img src="../assets/images/barchart.png" style="width: 100%;" />
 | 
			
		||||
 | 
			
		||||
# Usage
 | 
			
		||||
 | 
			
		||||
## Basic usage
 | 
			
		||||
 | 
			
		||||
```csharp
 | 
			
		||||
AnsiConsole.Render(new BarChart()
 | 
			
		||||
    .Width(60)
 | 
			
		||||
    .Label("[green bold underline]Number of fruits[/]")
 | 
			
		||||
    .CenterLabel()
 | 
			
		||||
    .AddItem("Apple", 12, Color.Yellow)
 | 
			
		||||
    .AddItem("Orange", 54, Color.Green)
 | 
			
		||||
    .AddItem("Banana", 33, Color.Red));
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## Add items with converter
 | 
			
		||||
 | 
			
		||||
```csharp
 | 
			
		||||
// Create a list of fruits
 | 
			
		||||
var items = new List<(string Label, double Value)>
 | 
			
		||||
{
 | 
			
		||||
    ("Apple", 12),
 | 
			
		||||
    ("Orange", 54),
 | 
			
		||||
    ("Banana", 33),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Render bar chart
 | 
			
		||||
AnsiConsole.Render(new BarChart()
 | 
			
		||||
    .Width(60)
 | 
			
		||||
    .Label("[green bold underline]Number of fruits[/]")
 | 
			
		||||
    .CenterLabel()
 | 
			
		||||
    .AddItems(items, (item) => new BarChartItem(
 | 
			
		||||
        item.Label, item.Value, Color.Yellow)));
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## Add items implementing IBarChartItem
 | 
			
		||||
 | 
			
		||||
```csharp
 | 
			
		||||
public sealed class Fruit : IBarChartItem
 | 
			
		||||
{
 | 
			
		||||
    public string Label { get; set; }
 | 
			
		||||
    public double Value { get; set; }
 | 
			
		||||
    public Color? Color { get; set; }
 | 
			
		||||
 | 
			
		||||
    public Fruit(string label, double value, Color? color = null)
 | 
			
		||||
    {
 | 
			
		||||
        Label = label;
 | 
			
		||||
        Value = value;
 | 
			
		||||
        Color = color;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Create a list of fruits
 | 
			
		||||
var items = new List<Fruit>
 | 
			
		||||
{
 | 
			
		||||
    new Fruit("Apple", 12, Color.Yellow),
 | 
			
		||||
    new Fruit("Orange", 54, Color.Red),
 | 
			
		||||
    new Fruit("Banana", 33, Color.Green),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Render bar chart
 | 
			
		||||
AnsiConsole.Render(new BarChart()
 | 
			
		||||
    .Width(60)
 | 
			
		||||
    .Label("[green bold underline]Number of fruits[/]")
 | 
			
		||||
    .CenterLabel()
 | 
			
		||||
    .AddItem(new Fruit("Mango", 3))
 | 
			
		||||
    .AddItems(items));
 | 
			
		||||
```
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
Title: Calendar
 | 
			
		||||
Order: 2
 | 
			
		||||
Order: 3
 | 
			
		||||
RedirectFrom: calendar
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
Title: Canvas Image
 | 
			
		||||
Order: 5
 | 
			
		||||
Order: 6
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
To add [ImageSharp](https://github.com/SixLabors/ImageSharp) superpowers to 
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
Title: Canvas
 | 
			
		||||
Order: 4
 | 
			
		||||
Order: 5
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
`Canvas` is a widget that allows you to render arbitrary "pixels" 
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
Title: Figlet
 | 
			
		||||
Order: 3
 | 
			
		||||
Order: 4
 | 
			
		||||
RedirectFrom: figlet
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
Title: Rule
 | 
			
		||||
Order: 1
 | 
			
		||||
Order: 2
 | 
			
		||||
RedirectFrom: rule
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user