-
Notifications
You must be signed in to change notification settings - Fork 833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Label: incorrect horizontal alignment for multiline strings #3859
Comments
LabelStyle
properties
Thanks for reporting this @karlipl! Recently a lot of plottable objects were upgraded to use advanced label styling features, but I think In a pinch you could place a text object over your bars! Actually, that has the same problem. Here's the code I used to test that: using ScottPlot;
ScottPlot.Plot plot = new();
Bar[] bars =
[
new()
{
Position = 1,
Value = 60000,
BorderColor = Colors.Transparent,
FillColor = Color.FromHex("E56646"),
ValueBase = 0,
},
new ()
{
Position = 1,
Value = 60000 + 40000,
BorderColor = Colors.Transparent,
FillColor = Color.FromHex("68BC5A"),
ValueBase = 60000,
}
];
plot.Add.Bars(bars);
plot.Add.Text($"Row top\nRow in the middle\nRow bottom", bars[0].Position, bars[0].Value);
plot.Add.Text($"Row top\nRow in the middle\nRow bottom", bars[1].Position, bars[1].Value);
foreach (var txt in plot.GetPlottables<ScottPlot.Plottables.Text>())
{
txt.LabelFontColor = Colors.White;
txt.LabelBold = true;
txt.LabelFontSize = 16;
txt.Alignment = Alignment.UpperCenter;
}
plot.Title(ScottPlot.Version.VersionString);
plot.SavePng("demo.png", 400, 300).LaunchFile(); I think the core issue is that horizontal centering of multiline labels is failing. It's aligning horizontally based on the first line, not the longest line. Here's a simpler demonstration of this issue: ScottPlot.Plot plot = new();
var txt = plot.Add.Text($"aaa\nbbbbbbbbbbb\nccc", 0, 0);
txt.Alignment = ScottPlot.Alignment.MiddleCenter;
txt.LabelBackgroundColor = ScottPlot.Colors.SkyBlue;
plot.SavePng("demo.png", 400, 300).LaunchFile(); I'll mark this issue high priority and use it to track fixing this problem too 👍 |
LabelStyle
properties
Hi, thanks for the reply and working on this. Regards |
Question: Hi, I have a barplot with a multiline label. Is there a way to center each row of the label?
I would like the following result:
-------Row top
--Row in the middle
-----Row bottom
ScottPlot Version: ScottPlot 5.0.34
Code Sample:
This is just a snippet of my code. I could provide a minimum full example if needed.
I would really appreciate some help.
Regards
Karl
The text was updated successfully, but these errors were encountered: