Horizontal Bar Chart in C#
Draw horizontal bar charts in C# with AddBar — room for long category labels, natural for ranked lists. Self-contained SVG, MIT licensed, zero dependencies.
Horizontal Bar Chart
ChartType.Bar — bars grow left-to-right.
When to use a horizontal bar chart
Reach for it when
- Long category names. Horizontal bars give the label a full line of text instead of a rotated sliver.
- Ranked lists — top products, slowest endpoints — sorted descending so the eye reads down the order.
- Many categories. A bar chart scrolls vertically without the labels colliding.
Use something else when
- Time on the category axis. Readers expect time to run left to right; use a column chart.
- Two or three categories, where the horizontal layout wastes the page's width.
- Negative and positive values you want compared precisely — the shared centre baseline is easier to read in a column chart.
Horizontal Bar Chart in C#
Lifted verbatim from the chart types reference, so it compiles against the shipped API. See the API reference for every overload and the exact data types each series method accepts.
string svg = ChartBuilder.Create()
.Title("Population by City")
.Size(700, 420)
.XAxis(x => x.Categories.AddRange(
new[] { "Tokyo","Delhi","Shanghai","São Paulo","Mexico City","Cairo" }))
.YAxis(y => { y.Title = "Population (M)"; y.Min = 0; y.Max = 40; })
.AsAnimated()
.Series(s => s
.AddBar("Population (M)",
new double[] { 37.4, 32.9, 27.1, 22.4, 21.9, 21.3 },
cfg => cfg.Color(ChartColor.ChartBlue)))
.RenderToSvg();Install
dotnet add package TerraFluent.Chart.Reporting
- MIT licensed — free for commercial use, no chart limits, no watermarks.
- Zero dependencies — nothing but the .NET base class library.
- netstandard2.0 through net10.0 — .NET Framework 4.6.1+, .NET Core 2.0+, and every modern release.
- Output is one SVG string — embed it in HTML, a PDF, or a Word document.