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
Axis Title alignment issue
Moderator: Queue Moderators
Axis Title alignment issue
- Attachments
-
- UnalignedTitles.PNG (7.58 KiB) Viewed 7294 times
-
- Posts: 557
- Joined: Mon Mar 14, 2016 9:22 am
Re: Axis Title alignment issue
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):
Hope this helps.
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();
}
Re: Axis Title alignment issue
Thank you very much! Your suggestion was very helpful, I believe we've fixed the issue.