LegendBox

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
paultobey
Posts: 21
Joined: Mon Dec 09, 2013 7:27 pm

LegendBox

Post by paultobey » Wed Jan 22, 2014 3:34 pm

Hi,

I'm adjusting my XY chart margins to make room for the legend below the graph surface. However, with many traces on the chart the legend box is now several rows. How (or when) can I adjust margins? What I've attempted is the following after all data series have been added:

// Chart created and series added here...

// Adjust margin on bottom area to allow legend + cursor enough room to avoid overlapping (the legend is in
// front which we don't want).
System.Drawing.Rectangle legendRect = Chart1.ViewXY.LegendBox.GetRenderedRect();
Chart1.ViewXY.Margins = new Thickness(Chart1.ViewXY.Margins.Left,
Chart1.ViewXY.Margins.Top,
Chart1.ViewXY.Margins.Right,
Chart1.ViewXY.Margins.Bottom + legendRect.Height + 10);

// Update complete.
Chart1.EndUpdate();

However, GetRenderedRect() is 0,0,0,0; not very useful. I see no other clear chance to adjust the margin before rendering the chart. Obviously I don't want to render it once with the wrong margin then redo. Suggestions?

Paul T.

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: LegendBox

Post by ArctionPasi » Wed Jan 22, 2014 9:23 pm

Hi Paul,

probably making a special handling in AfterRendering event.

Code: Select all


        bool m_bFirstTime = true; 

        void m_chart_AfterRendering(LightningChartUltimate.LightningChartUltimate chart)
        {
            if (m_bFirstTime)
            {
               
                System.Drawing.Rectangle legendRect = m_chart.ViewXY.LegendBox.GetRenderedRect();

                m_chart.ViewXY.Margins = new Thickness(m_chart.ViewXY.Margins.Left,
                m_chart.ViewXY.Margins.Top,
                m_chart.ViewXY.Margins.Right,
                m_chart.ViewXY.Margins.Bottom + legendRect.Height + 10);

                m_bFirstTime = false;

                m_chart.InvalidateVisual();
               
            }

        }

        
:?
LightningChart Support Team, PT

paultobey
Posts: 21
Joined: Mon Dec 09, 2013 7:27 pm

Re: LegendBox

Post by paultobey » Wed Jan 22, 2014 10:46 pm

Yes, that worked.

Thanks,
Paul T.

Post Reply