ViewXY X Axis value labels - value dependent formatting

Need help in implementing some specific function to your LightningChart Ultimate powered application? Post a question and get code snippets from other LightningChart Ultimate community members.

Moderator: Arction_LasseP

Post Reply
hazha
Posts: 1
Joined: Wed Feb 07, 2018 10:22 pm

ViewXY X Axis value labels - value dependent formatting

Post by hazha » Thu Mar 29, 2018 8:56 pm

Hi,

I'm trying to create a scrolling ViewXY chart with the x-axis labels displaying in the format HH:mm:ss initially and d:HH:mm:ss after the chart has been scrolling for longer than 24 hours.

I've tried some workarounds but are having some problems with them still:

1. I can't create custom formatting strings with optional days (eg. [d]:HH:mm:ss) due to .Net limitations so I can only use the standard format strings. I would like to know if there's a converter of some kind that I can use to implement some value dependent ToString() methods.
2. When I tried to use the standard format strings, I've set the ValueType to Number but it seems the chart is still calling ToString for a DateTime object rather than a TimeSpan object. Due to this, I'm getting "1/1/0001 12:00:00 AM" as my initial label when using the generic format "g".

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

Re: ViewXY X Axis value labels - value dependent formatting

Post by ArctionKestutis » Tue Apr 03, 2018 10:24 am

Hi,

Sorry for the delayed response.
LightningChart's labels auto formatting logic tries to do close to that you asked. That is, if XAxis.AutoFormatLables is enables and XAxis.ValueType==DateTime, when for step (between ticks)
<1 sec format "mm:ss.(f)" is used;
>1 & <300 sec format "HH:mm:ss" is used;
above that used format close to current culture’s short date and time format.

If you want to make your own rules, just disable XAxis.AutoFormatLables and use XAxis.LabelsTimeFormat. The formatting string used could be changed based on the Axis range: use XAxis.RangeChanged event handler to check new range and react accordingly.

Hope this helps.
All the best.

zzoubian
Posts: 3
Joined: Wed May 16, 2018 3:17 pm

Re: ViewXY X Axis value labels - value dependent formatting

Post by zzoubian » Wed May 16, 2018 5:40 pm

Hello,

When setting the XAxis.LabelsTimeFormat to "d / HH:mm:ss", the day shows up as either the current day (i.e. 16, for May 16) when using a value type of DateTime, and 1, when using the value type of Time. Is it possible to show the label as 0 / HH:mm:ss (0 days) when its less then 24 hours, and 1 / HH:mm:ss when greater than 24 hrs?

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

Re: ViewXY X Axis value labels - value dependent formatting

Post by ArctionKestutis » Fri May 18, 2018 9:17 am

Hello,

When setting LabelsTimeFormat property, the DateTime.ToString() method's parameters string applies. You can find more about available options here.
If you could not find suitable option, you can use Axis.FormatValueLabel event. For example,

Code: Select all

        _chart.ViewXY.YAxes[0].FormatValueLabel += YAxis_FormatValueLabel;

        private string YAxis_FormatValueLabel(object sender, FormatValueLabelEventArgs e)
        {
            string strUnits = "mV";
            return string.Format("{0} {1}", e.Value, strUnits);
        }
Or you could use CustomTicks, see corresponding example in our Demo App.

Hope this helps.
All the best.

zzoubian
Posts: 3
Joined: Wed May 16, 2018 3:17 pm

Re: ViewXY X Axis value labels - value dependent formatting

Post by zzoubian » Fri May 18, 2018 4:18 pm

Thank you, the Axis.FormatValueLabel event worked for me!

Post Reply