|
PDFsharp - moved to http://forum.pdfsharp.net/ Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
|
Important Notice:
We regret to inform you that our free phpBB forum hosting service will be discontinued by the end of June 30, 2024.
If you wish to migrate to our paid hosting service, please contact billing@hostonnet.com.
View previous topic :: View next topic |
Author |
Message |
MightyKnighty
Joined: 18 May 2008 Posts: 5 Location: UK
|
Posted: Sun Jun 08, 2008 9:43 am Post subject: Displaying a chart legend using MigraDoc |
|
|
How can a display a legend in a chart in a MigraDoc document.
In pdfsharp I used chart.legend
In migraDoc I tried to use
Legend legend = chart.RightArea.AddLegend();
to add a legend on the right of a Bar2D chart type.
but then I get the following error:
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="MigraDoc.Rendering"
StackTrace:
at MigraDoc.Rendering.TopDownFormatter.FormatOnAreas(XGraphics gfx, Boolean topLevel) in D:\My Documents\Visual Studio 2008\Projects\MigraDocLite\MigraDoc.Rendering\MigraDoc.Rendering\TopDownFormatter.cs:line 80
at MigraDoc.Rendering.FormattedTextArea.Format(XGraphics gfx) in D:\My Documents\Visual Studio 2008\Projects\MigraDocLite\MigraDoc.Rendering\MigraDoc.Rendering\FormattedTextArea.cs:line 57
......
Any suggestions on how I can get a legend to appear.
Many thanks |
|
Back to top |
|
|
ldelabre
Joined: 12 Apr 2008 Posts: 10
|
Posted: Fri Jun 13, 2008 7:39 am Post subject: |
|
|
I've got the same error
Any suggestions ? |
|
Back to top |
|
|
ldelabre
Joined: 12 Apr 2008 Posts: 10
|
Posted: Fri Jun 13, 2008 8:19 am Post subject: |
|
|
Ok here's what I did (and it seems to work) :
in MigraDocLite\MigraDoc.Rendering\MigraDoc.Rendering\TopDownFormatter.cs
Inside public void FormatOnAreas(XGraphics gfx, bool topLevel)
Change
Code: |
DocumentObject docObj = this.elements[idx];
Renderer renderer = Renderer.Create(gfx, this.documentRenderer, docObj, this.areaProvider.AreaFieldInfos);
renderer.MaxElementHeight = maxHeight;
if (topLevel && this.documentRenderer.HasPrepareDocumentProgress)
{
this.documentRenderer.OnPrepareDocumentProgress(this.documentRenderer.ProgressCompleted + idx + 1,
this.documentRenderer.ProgressMaximum);
}
// "Slightly hacked" for legends: they are rendered as part of the chart.
// So they are skipped here.
if (renderer == null)
{
ready = idx == this.elements.Count - 1;
if (ready)
this.areaProvider.StoreRenderInfos(renderInfos);
++idx;
continue;
}
|
to
Code: |
DocumentObject docObj = this.elements[idx];
Renderer renderer = Renderer.Create(gfx, this.documentRenderer, docObj, this.areaProvider.AreaFieldInfos);
if (topLevel && this.documentRenderer.HasPrepareDocumentProgress)
{
this.documentRenderer.OnPrepareDocumentProgress(this.documentRenderer.ProgressCompleted + idx + 1,
this.documentRenderer.ProgressMaximum);
}
// "Slightly hacked" for legends: they are rendered as part of the chart.
// So they are skipped here.
if (renderer == null)
{
ready = idx == this.elements.Count - 1;
if (ready)
this.areaProvider.StoreRenderInfos(renderInfos);
++idx;
continue;
}
renderer.MaxElementHeight = maxHeight;
|
(I moved the renderer.MaxElementHeight = maxHeight ...) |
|
Back to top |
|
|
MightyKnighty
Joined: 18 May 2008 Posts: 5 Location: UK
|
Posted: Sat Jun 14, 2008 11:37 am Post subject: Thank Idelabre |
|
|
Thank Idelabre
You a true Star
That worked great for me too....
I now have legends for my charts ....
Hooray. |
|
Back to top |
|
|
ldelabre
Joined: 12 Apr 2008 Posts: 10
|
Posted: Sat Jun 14, 2008 2:29 pm Post subject: |
|
|
Thank you
Anytime |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|