MigraDoc Chart Legend does not Word Wrap
I've been working with MigraDoc to generate PDF reports. It does most of what we need but comes up short in a few areas.
One issue is with chart legends. If there are too many entries in the legend or some are too long, the legend extends off both sides of the page.
It looks like the library has no support for this issue. Has anyone figured out a way of dealing with this?
I tried contacting the authors about some custom development, but they took a week to respond and ignored my questions.
Just as an info, seems like cloudflare blocked the access to your img. 😮💨
And in the matter of responses from the authors, I would assume they are either at one of the conferences that are actually running or just on a vacation. keep in mind, that they are maintaining this library on top of their 9/5 schedule and totally free. so stay patient, they will reach out. 👌
@Phil-oops Funny. It shows for me. I'll update the link, although I'm not expecting any assistance at this stage.
In the matter of you chart legend, on what area did you bind it?
ps.: I know why I do such things with html. 😬
@Phil-oops The footer. Does my image show for you now?
Yes now I can see it. So you create the legend like
var xSeries = chart.XValues.AddXSeries(); xSeries.Add("X1", "X2", "X3", "Xn");
var legend = chart.FooterArea.AddLegend()?
if this is the case, the legend should have properties like:
legend.LineFormat.Width = Unit.FromPoint(1) I'm not that deep into the pdf drawiing with pdf sharp but I would assume you could either use the XTextFormat class or have you just tried to create another xSeries object and add the overflowing elements?
Thought so:
chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Line; series.MarkerStyle = MarkerStyle.None; series.LineFormat.Color = Colors.Red;XSeries xseries = chart.XValues.AddXSeries();
therefore I would assume, that you could do something similar with the footer. 🤔
therefore I would
Maybe you see another path from here to configure what you need. 👌
But setting the width on 1 should probably do the jon 🧐
@Phil-oops Setting the width of the line to 1 is altering the line on the chart. I don't see that has anything to do with the legend.
in the end most of it works like plain html. and i hoped by setting the width it would set a boundary. But the properties on legend.Format seem promising especially the "KeepTogether" or
legend.Format.Alignment = ParagraphAlignment.Justify;
that's what i was searching for =>
"Justified alignment is a text formatting technique where the text is aligned evenly along both the left and right margins. This creates a clean and professional look, often used in newspapers, books, and formal documents. When text is justified, extra space is added between words to ensure that each line of text aligns perfectly with both margins."
@Phil-oops Thanks. Yes, you are correct that you can save the results of AddLegend(), and it gives you access to the legend object. And I can see there are various formatting properties such as Alignment.
However, Alignment has no effect that I can see on word wrapping the legend. And I don't see any other properties that seem to affect that either.
I suspect regular word wrap would not work here as lines could be broken within category names, if they had spaces. As best I can see, the legend does appear to support word wrap at all.
I tried contacting the authors about some custom development, but they took a week to respond and ignored my questions.
People sometimes go on vacation. See #305 .
I am pretty sure the solution has to do with the KeepTogether and KeepWithNext Properties. and it seems that the parent componenent overlay the configurations of the children.
@ThomasHoevel Yes, people go on vacation. But I contacted you through your website twice now with detailed explanation of the work we need. The response was that I had to provide details even though I provided complete details.
I've been trying to contact you with those details for more than two weeks now. And no one ever responded to my questions. No one said you cannot take a vacation! You are simply unresponsive!
@Phil-oops Those two properties have to do with relationships between paragraphs. Currently, my legend does not span multiple paragraphs. I am confident those properties are not related to the issue.
Okay last take. If i understand this right the series names are the ones which are showed in legend.
As simple as it might be, but have you just tried to put a linebreake / softbreak after one of the names.?
ps.: That will be my last take on this topic. hope you will soon find a solution for your problem
The response was that I had to provide details even though I provided complete details.
We cannot make a contract based on the "complete details" you provided, so we probably will have some questions asking for more details.
You are simply unresponsive!
Today is my first working day after my vacation and I have a backlog of e-mails to work through.
The fellow worker who replied to you is on a sick leave today.
@Phil-oops Yeah, I appreciate you looking. I've actually spent a lot of time on this. I've tried literally everything, including inserting newlines. But I have built a custom routine that renders my own legend from scratch, with its own word wrap logic. And that's probably what we'll end up using. It's just unfortunate that the library doesn't handle this.
@ThomasHoevel I would have been happy to be asked questions if something about my details wasn't clear. But instead, I was just told to "provide details." That is my only complaint.
Anyway, that was two weeks ago. I wrote my own chart legend from scratch and it's probably going to do what we need.