PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Oct 31, 2024 11:06 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Sun Jun 08, 2008 9:43 am 
Offline

Joined: Sun May 18, 2008 12:46 pm
Posts: 5
Location: UK
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


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

Joined: Sat Apr 12, 2008 8:51 am
Posts: 10
I've got the same error :(

Any suggestions ?


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

Joined: Sat Apr 12, 2008 8:51 am
Posts: 10
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 ...)


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

Joined: Sun May 18, 2008 12:46 pm
Posts: 5
Location: UK
Thank Idelabre :D

You a true Star

That worked great for me too.... :idea:

I now have legends for my charts ....
Hooray. :lol:


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

Joined: Sat Apr 12, 2008 8:51 am
Posts: 10
Thank you ;)

Anytime 8)


Top
 Profile  
Reply with quote  
PostPosted: Sun Feb 07, 2010 10:35 pm 
Offline

Joined: Mon Nov 23, 2009 5:23 pm
Posts: 16
Can someone help me and show me an example how to add values to the legend?

I always get an error in ObjectModelMeta.SetValue because there is no value 'open' in

Code:
 ValueDescriptor vd = this.vds[name];
      if (vd == null)
        throw new ArgumentException(DomSR.InvalidValueName(name));


this is my try to create this legend:

Code:
Legend bsnLegend = chartRequests.RightArea.AddLegend();
            bsnLegend.SetValue("open", seriesOpen);


I haven't found any other entry in the forum and now used legend in the example.

Please help!

Thanks!


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 08, 2010 9:26 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3111
Location: Cologne, Germany
MH_2106 wrote:
I always get an error in ObjectModelMeta.SetValue because there is no value 'open' in


You can only set the members of a Legend (Format or Style).

I never used the charts so I have no clue what they do - but I presume the contents of the Legend comes automatically from the Series.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 30 guests


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 post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group