X Tutup
Skip to content

IsStacked BarSeries with LabelPlacement=Outside label not placed properly #1979

@innominate227

Description

@innominate227

Platform: Console app. SVG exported with OxyPlot.SkiaSharp.SvgExporter
.NET version: 6.0

Actual behaviour

The Orange series has LabelPlacement=Outside, but several of the labels are being placed incorrectly.
plot

Expected behaviour

All labels should be placed similar to labels 35-60.

Code

var data = Enumerable.Range(1, 12).Select(i => new { Cat = i, A = 30, B = 5 * i }).ToList();

var model = new PlotModel();

//category axis
var axis = new CategoryAxis { Key = "y", };
axis.Labels.AddRange(data.Select(d => d.Cat.ToString()));
model.Axes.Add(axis);

//values axis
model.Axes.Add(new LinearAxis { Minimum = 0, Maximum = 100, Key = "x", });

var seriesA = new BarSeries
{
    IsStacked = true,
    XAxisKey = "x",
    YAxisKey = "y",
    LabelFormatString = "{0:N0}",
    LabelPlacement = LabelPlacement.Middle,
};
seriesA.Items.AddRange(data.Select(d => new BarItem(d.A)));
model.Series.Add(seriesA);

var seriesB = new BarSeries
{
    IsStacked = true,
    XAxisKey = "x",
    YAxisKey = "y",
    LabelFormatString = "{0:N0}",
    //Inside and Base also put the labels in wrong places.  Middle works as expected.
    LabelPlacement = LabelPlacement.Outside,
};
seriesB.Items.AddRange(data.Select(d => new BarItem(d.B)));
model.Series.Add(seriesB);

using (var stream = File.Create(@"C:/tmp/plot.svg"))
{
    var svgExporter = new OxyPlot.SkiaSharp.SvgExporter { Width = 500, Height = 500 };                
    svgExporter.Export(model, stream);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup