Pie Chart in C#
Render pie charts in C# with AsPie and Add — outside labels with connector lines, legend placement, self-contained SVG. TerraFluent.Chart.Reporting, MIT.
Pie Chart
Pie chart with legend showing market share by vendor.
Pie — Label Placement
DataLabelRadius: inside, at edge, and outside with connector.
When to use a pie chart
Reach for it when
- Parts of a single whole that genuinely sums to 100% — market share, budget allocation.
- Three to six slices. Past that the small slices become indistinguishable wedges.
- When "roughly half" or "about a quarter" is the takeaway, not a precise ranking.
Use something else when
- Comparing slices of similar size. Humans compare angles badly; a bar chart makes the same comparison exact.
- Values that do not sum to a whole, or that can be negative.
- Change over time. Two pies side by side are far harder to read than one column or line chart.
Pie 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.
// Pie
string svg = ChartBuilder.Create()
.AsPie()
.Title("Market Share by Vendor")
.Size(600, 440)
.Labels("TerraFluent","Competitor A","Competitor B","Others")
.Legend(l => l.AtBottom())
.AsAnimated()
.Series(s => s
.Add("Market Share", new double[] { 38, 27, 21, 14 },
cfg => cfg.DataLabel.Show().Radius(1.2).Format("{value}%")))
.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.