Axis Title alignment issue

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
mobusek
Posts: 13
Joined: Tue Mar 27, 2018 2:16 pm

Axis Title alignment issue

Post by mobusek » Wed Mar 20, 2019 12:42 pm

Hello, I'm trying to sort through the different Axis Title and Label options to make sure that Axis Titles are aligned. If you look at the image below, you can see the placement of the Y Axis Titles seems determined by that axis' Labels. A longer Label pushes the Title further out. What I'm hoping to achieve is have the right-edge of all Titles align. So in this case, the bottom 3 Titles would move left to align with the top outermost title.

Is there any way to either automatically or manually achieve this kind of Title alignment? Thank you!

- Michael
Attachments
UnalignedTitles.PNG
UnalignedTitles.PNG (7.58 KiB) Viewed 6933 times

ArctionKestutis
Posts: 552
Joined: Mon Mar 14, 2016 9:22 am

Re: Axis Title alignment issue

Post by ArctionKestutis » Thu Mar 21, 2019 8:48 am

Hello,

The Axis Title could be positioned at fixed distance from Axis. For that you should set axisY.Title.DistanceToAxis property and disable _chart.ViewXY.AxisLayout.YAxisTitleAutoPlacement.
Only thing that you need is the distance's estimate. Here is my suggestion how you can do it in Axis.RangeChanged event handler (this is general solution for YAxes position on the left or on the right, but Title rotate by 90 deg):

Code: Select all

        private void YAxis_RangeChanged(object sender, RangeChangedEventArgs e)
        {
            // Estimate YAxis Title position
            float lCoord = float.MaxValue;
            float rCoord = float.MinValue;
            LightningChartUltimate chart = (sender as AxisY).OwnerView.OwnerChart;

            System.Drawing.Rectangle rect = chart.ViewXY.GetMarginsRect();

            // get left most YAxes point
            foreach (AxisY axisY in chart.ViewXY.YAxes)
            {
                if (!axisY.Visible)
                {
                    continue;
                }

                // get axis area, which includes Axis-line and Labels
                RectangleXY axRect = axisY.GetActiveAxisArea();
                if (axRect.Width == 0)
                {
                    // axis not yet rendered
                    continue;
                }

                // if Axis on the left edge
                if (axRect.X < rect.X && lCoord > axRect.X)
                {
                    lCoord = axRect.X;
               }

                // if Axis on the right edge
                if (axRect.X >= (rect.X + rect.Width) && rCoord < (axRect.X + axRect.Width) )
                {
                    rCoord = (axRect.X + axRect.Width);
                }

            }

            if (lCoord == float.MaxValue && rCoord == float.MinValue)
                return;


            // set Y Title to fixed position from Axis
            chart.BeginUpdate();

            // set Y Title to fixed position from Axis
            chart.ViewXY.AxisLayout.YAxisTitleAutoPlacement = false;

            foreach (AxisY axisY in chart.ViewXY.YAxes)
            {
                if (!axisY.Visible)
                {
                    continue;
                }

                // get axis area, which includes Axis-line and Labels
                RectangleXY axRect = axisY.GetActiveAxisArea();
                if (axRect.Width == 0)
                {
                    // axis not yet rendered
                    continue;
                }

                // if Axis on the left edge
                if (axRect.X < rect.X && lCoord != float.MaxValue)
                {
                    axisY.Title.HorizontalAlign = YAxisTitleAlignmentHorizontal.Left;
                    axisY.Title.DistanceToAxis = (axRect.X + axRect.Width) - (int)lCoord + 5;
                }

                // if Axis on the right edge
                if (axRect.X >= (rect.X + rect.Width) && rCoord != float.MinValue)
                {
                    axisY.Title.HorizontalAlign = YAxisTitleAlignmentHorizontal.Right;
                    axisY.Title.DistanceToAxis = (int)rCoord - axRect.X + 5;
                }
            }

            chart.EndUpdate();
        }
Hope this helps.

mobusek
Posts: 13
Joined: Tue Mar 27, 2018 2:16 pm

Re: Axis Title alignment issue

Post by mobusek » Fri Mar 22, 2019 7:41 pm

Thank you very much! Your suggestion was very helpful, I believe we've fixed the issue.

Post Reply