ScottPlot.NET
GitHub Repo stars

Legend Marker Shape Override with auto color

Use the legend shape override to force all legend items to display using the given marker shape. Color is determined automatically in this example.

ScottPlot.Plot myPlot = new();

List<PieSlice> slices =
[
    new PieSlice() { Value = 5, FillColor = Colors.Red, Label = "Red", LegendText = "R" },
    new PieSlice() { Value = 2, FillColor = Colors.Orange, Label = "Orange" },
    new PieSlice() { Value = 8, FillColor = Colors.Gold, Label = "Yellow" },
    new PieSlice() { Value = 4, FillColor = Colors.Green, Label = "Green", LegendText = "G" },
    new PieSlice() { Value = 8, FillColor = Colors.Blue, Label = "Blue", LegendText = "B" },
];

myPlot.Legend.MarkerShapeOverride = MarkerShape.FilledCircle;

var pie = myPlot.Add.Pie(slices);

myPlot.Axes.Frameless();
myPlot.HideGrid();
myPlot.ShowLegend();

myPlot.SavePng("demo.png", 400, 300);
This recipe is one of many in the Legends category