Displaying multiple X-axis titles

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

Displaying multiple X-axis titles

Post by mobusek » Wed Jan 29, 2020 4:51 pm

Occasionally we need to overlap multiple 2D plots. For example I might need to plot Position-X vs Position-Y from DeviceA and overlap Position-X vs Position-Y from DeviceB.

The only problem I'm having is how to display the X-axis titles in the best way. For the y-axis titles, I can show something like Position-Y (DeviceA) and Position-Y (DeviceB) as the titles of the FreeformPointLineSeries. And they can be different colors that correspond to the two lines on the chart.

But there doesn't seem to be an equivalent way to handle the X axis titles. I'd like to do the exact same thing - have two titles below the chart that can be different colors. But the X Axis type only supports a single axis title with one color. Is there a way to accomplish this, or to approximate it somehow?

Thank you.

- Michael

Arction_LasseP
Posts: 141
Joined: Wed Mar 27, 2019 1:05 pm

Re: Displaying multiple X-axis titles

Post by Arction_LasseP » Thu Jan 30, 2020 7:57 am

Hello,

In general, there can be only one title per axis. Therefore, if you need to show two differently colored titles, some other means has to be used. There are several possibilities:

-If you are not using the Units text with your X-axis, you can use that as a secondary title:

Code: Select all

axisX.Units.Visible = true;
axisX.Units.Text = "Another title";
axisX.Units.HorizontalAlign = XAxisTitleAlignmentHorizontal.ToValue;
axisX.Units.AlignToValue = 5;
axisX.Units.Font.Size = 24;
axisX.Units.Color = Colors.Green;
-You can use an Annotation and place it below the graph. Just disable all the fill settings and show only the text:

Code: Select all

AnnotationXY anno = new AnnotationXY(_chart.ViewXY, axisX, _chart.ViewXY.YAxes[0]);
anno.ClipInsideGraph = false;
anno.Fill.Style = RectFillStyle.None;
anno.Style = AnnotationStyle.Rectangle;
anno.Shadow.Visible = false;
anno.BorderVisible = false;
anno.LocationCoordinateSystem = CoordinateSystem.AxisValues;
anno.LocationAxisValues.SetValues(15, _chart.ViewXY.YAxes[0].Minimum - 3);
anno.MouseInteraction = false;
_chart.ViewXY.Annotations.Add(anno);
The downside of this is that if you zoom/pan the axes, you need to update the position of the Annotation. Either use RangeChanged -event or use screen coordinates to determine the position. A SeriesEventMarker can also be used instead of Annotation.

-You can also use a secondary X-axis. Hide all the labels and ticks and switch colors to transparent so that only the title is visible.

Code: Select all

axisX2.AxisColor = Colors.Transparent;
axisX2.LabelsVisible = false;
axisX2.MajorDivTickStyle.Visible = false;
axisX2.MinorDivTickStyle.Visible = false;
axisX2.MouseScaling = false;
Hope this is helpful.
Best regards,
Lasse

Post Reply