Legend loses it's orientation when added as a panel

Open Beginner friendly
#5,267 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
csharp

Research direction

Start with the code sample using ScottPlot.Panels.LegendPanel, myPlot.Legend, and myPlot.ShowLegend(pan.Edge), focusing on how the legend is transferred into the panel. Reproduce the sample with ScottPlot 5.1.59 and verify that setting Orientation to Vertical before adding the panel remains effective in the saved PNG.

Written by the indexing model from the issue text.

Description

Issue:

ScottPlot Version: 5.1.59

Code Sample:

ScottPlot.Plot myPlot = new();

PieSlice slice1 = new() { Value = 5, FillColor = Colors.Red, Label = "alpha", LegendText = "alpha"  };
PieSlice slice2 = new() { Value = 2, FillColor = Colors.Orange, Label = "beta", LegendText = "beta" };
PieSlice slice3 = new() { Value = 8, FillColor = Colors.Gold, Label = "gamma", LegendText = "gamma" };
PieSlice slice4 = new() { Value = 4, FillColor = Colors.Green, Label = "delta", LegendText = "delta" };
PieSlice slice5 = new() { Value = 8, FillColor = Colors.Blue, Label = "epsilon", LegendText = "epsilon" };

List<PieSlice> slices = new() { slice1, slice2, slice3, slice4, slice5 };

myPlot.ShowLegend();
// setup the pie to display slice labels
var pie = myPlot.Add.Pie(slices);
pie.SliceLabelDistance = 1.3;


// hide unnecessary plot components
myPlot.Axes.Frameless();
myPlot.HideGrid();
myPlot.Legend.OutlineStyle = ScottPlot.LineStyle.None;
myPlot.Legend.ShadowColor = Colors.Transparent;
//if you change orientation before adding to panel, it loses it and defaults to horizontal
myPlot.Legend.Orientation = Orientation.Vertical;

ScottPlot.Panels.LegendPanel pan = new(myPlot.Legend);
pan.Alignment = Alignment.MiddleCenter;
pan.Edge = Edge.Bottom;
myPlot.ShowLegend(pan.Edge);

//if you change it after adding the legend panel, it's ok, but i don't know if there are other settings that get lost too
//myPlot.Legend.Orientation = Orientation.Vertical;


myPlot.SavePng("bug.png");

This shows horizontal legend, even though i defined vertical above
Image

Dominant language
C#
Stars
6.8k
Forks
1k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ScottPlot/ScottPlot

All issues in ScottPlot/ScottPlot

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.