Margin for Titles

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
frank
Posts: 51
Joined: Tue Mar 25, 2014 9:04 am

Margin for Titles

Post by frank » Fri Jan 30, 2015 12:27 pm

Hi,

I'm using the AxisX.Title to display the dimension with the following code

Code: Select all

axisX.Title.HorizontalAlign = XAxisTitleAlignmentHorizontal.Right;
axisX.Title.VerticalAlign = XAxisTitleAlignmentVertical.Top;
axisX.Title.Text = ...
How can I move the Title just some pixels away from the right border?

Regards,
Frank
Attachments
title.png
title.png (1.41 KiB) Viewed 10122 times

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

Re: Margin for Titles

Post by ArctionPasi » Sat Jan 31, 2015 9:23 am

Good question. There's no Offset property in axis titles. :|

So this must be made by setting Title.HorizontalAlign = ToValue, and an axis.RangeChanged event handler, and update axis title's AlignToValue property there, based on screen coordinate the title must be at.

Code: Select all

m_chart.ViewXY.XAxes[0].Title.HorizontalAlign = XAxisTitleAlignmentHorizontal.ToValue; 
m_chart.ViewXY.XAxes[0].RangeChanged += new AxisBase.RangeChangedHandler(ExamplePointLineSeriesXY_RangeChanged);


void ExamplePointLineSeriesXY_RangeChanged(double newMin, double newMax, AxisBase axis, ref bool cancelRendering)
        {
            cancelRendering = true; 
            m_chart.BeginUpdate();

            AxisX xAxis = axis as AxisX; 
            int textWidth =  m_chart.MeasureText(xAxis.Title.Text, xAxis.Title.Font).X;
            int offset = -10;//Using 10 pixels offset to the left from right margin (center of the text). 
            int newCencterCoordOfTitle = m_chart.ViewXY.GetMarginsRect().Right - textWidth / 2 + offset;
            double axisValueToAlignTo;
            xAxis.CoordToValue(newCencterCoordOfTitle, out axisValueToAlignTo, false);
            xAxis.Title.AlignToValue = axisValueToAlignTo; 
            m_chart.EndUpdate(); 
        }

Also call the same routine in SizeChanged event handler.

:?
LightningChart Support Team, PT

frank
Posts: 51
Joined: Tue Mar 25, 2014 9:04 am

Re: Margin for Titles

Post by frank » Mon Feb 02, 2015 1:19 pm

Hi Pasi,

thanks for the solution. But on Zooming and Scrolling the label flickers all over the chart.
Could you make the "Offset for Titles" a feature-request for one of the next versions, or would that be to complicated?

Best regards,
Frank
Attachments
Labels.png
Labels.png (10.18 KiB) Viewed 10107 times

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

Re: Margin for Titles

Post by ArctionPasi » Mon Feb 02, 2015 3:58 pm

It's not that complicated to add, but the main concern is that we have already a hundred improvements pending for future development. All I can promise now, we will try to find time to implement this in v.7.
LightningChart Support Team, PT

frank
Posts: 51
Joined: Tue Mar 25, 2014 9:04 am

Re: Margin for Titles

Post by frank » Mon Feb 02, 2015 4:06 pm

Thanks. As long as V.7 won't take several years to be released I think it's sufficiently early.

Btw: I'm missing a "thumbs up" smiley ;)

Post Reply