ScottPlot.NET
GitHub Repo stars

Labels on Top

Bars with labels are rendered one at a time by default, but this makes it possible for bar labels to get overlapped by other bars. Bar chars may be configured to render labels last, even above other plottables.

ScottPlot.Plot myPlot = new();

double[] values = Generate.Consecutive(5, first: 1);

// create two bar plots
var bars1 = myPlot.Add.Bars(values);
var bars2 = myPlot.Add.Bars(values);

// enable the LabelsOnTop feature on one of the bars
bars2.LabelsOnTop = true;

// give each bar a label and style it to demonstrate the effect
static void StyleBar(ScottPlot.Plottables.BarPlot barPlot, double xOffset)
{
    barPlot.ValueLabelStyle.FontSize = 32;
    for (int i = 0; i < barPlot.Bars.Count; i++)
    {
        var bar = barPlot.Bars[i];
        bar.Label = i.ToString();
        bar.CenterLabel = true;
        bar.Position = i * .5 + xOffset;
        bar.FillColor = bar.FillColor.WithAlpha(.9);
    }
}

StyleBar(bars1, 0);
StyleBar(bars2, 4);

myPlot.Add.Text("Default", 0, 6);
myPlot.Add.Text("LabelsOnTop", 4, 6);

myPlot.HideGrid();

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