Skip to content

Bar: add option to have text labels render last #4855

@bclehmann

Description

@bclehmann

Issue:

It's possible to clip a bar beneath the one before it. Reported by Semaphor in the discord

Image

ScottPlot Version: Replicated on main

Code Sample: See http://scottplot.net/faq/repro/ for tips about creating reproducible code samples

 var bars = new List<ScottPlot.Bar>();

 for (int x = 0; x < 2; x++)
 {
     double[] values = Generate.Ones(10);
     values[0] = 0.1;

     double nextBarBase = 0;

     for (int i = 0; i < values.Length; i++)
     {
         ScottPlot.Bar bar = new()
         {
             Value = nextBarBase + values[i],
             ValueBase = nextBarBase,
             Label = "My Label",
             CenterLabel = true,
             Position = x,
         };

         bars.Add(bar);

         nextBarBase += values[i];
     }
 }

 myPlot.Add.Bars(bars).ValueLabelStyle = new LabelStyle() { FontSize = 48 };

 // use custom tick labels on the bottom
 ScottPlot.TickGenerators.NumericManual tickGen = new();
 for (int x = 0; x < 4; x++)
 {
     tickGen.AddMajor(x, $"Q{x + 1}");
 }
 myPlot.Axes.Bottom.TickGenerator = tickGen;

 myPlot.Legend.Orientation = Orientation.Horizontal;
 myPlot.ShowLegend(Alignment.UpperRight);

 // tell the plot to autoscale with no padding beneath the bars
 myPlot.Axes.Margins(bottom: 0, top: .3);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions