PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index PDFsharp - moved to http://forum.pdfsharp.net/
Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

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.
Displaying a chart legend using MigraDoc

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/
View previous topic :: View next topic  
Author Message
MightyKnighty



Joined: 18 May 2008
Posts: 5
Location: UK

PostPosted: Sun Jun 08, 2008 9:43 am    Post subject: Displaying a chart legend using MigraDoc Reply with quote

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
View user's profile Send private message
ldelabre



Joined: 12 Apr 2008
Posts: 10

PostPosted: Fri Jun 13, 2008 7:39 am    Post subject: Reply with quote

I've got the same error Sad

Any suggestions ?
Back to top
View user's profile Send private message
ldelabre



Joined: 12 Apr 2008
Posts: 10

PostPosted: Fri Jun 13, 2008 8:19 am    Post subject: Reply with quote

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
View user's profile Send private message
MightyKnighty



Joined: 18 May 2008
Posts: 5
Location: UK

PostPosted: Sat Jun 14, 2008 11:37 am    Post subject: Thank Idelabre Reply with quote

Thank Idelabre Very Happy

You a true Star

That worked great for me too.... Idea

I now have legends for my charts ....
Hooray. Laughing
Back to top
View user's profile Send private message
ldelabre



Joined: 12 Apr 2008
Posts: 10

PostPosted: Sat Jun 14, 2008 2:29 pm    Post subject: Reply with quote

Thank you Wink

Anytime Cool
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/ All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own YouTube Clone

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com