Page 1 of 1

ViewXY X Axis value labels - value dependent formatting

Posted: Thu Mar 29, 2018 8:56 pm
by hazha
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".

Re: ViewXY X Axis value labels - value dependent formatting

Posted: Tue Apr 03, 2018 10:24 am
by ArctionKestutis
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.

Re: ViewXY X Axis value labels - value dependent formatting

Posted: Wed May 16, 2018 5:40 pm
by zzoubian
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?

Re: ViewXY X Axis value labels - value dependent formatting

Posted: Fri May 18, 2018 9:17 am
by ArctionKestutis
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.

Re: ViewXY X Axis value labels - value dependent formatting

Posted: Fri May 18, 2018 4:18 pm
by zzoubian
Thank you, the Axis.FormatValueLabel event worked for me!