SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
If I make my own implementation of AxisLabelprovider for a CategoryDatetimeAxis I get different DateTime.Kind settings depending on the function called to format a label.
I put in the values as DateTime.Kind = DateTimeKind.Utc to the DataSeries<DateTime, double>
I have this implementation for my labelprovider:
public class CategoryAxisLabelProvider : TradeChartAxisLabelProvider
public override string FormatLabel(IComparable dataValue)
{
DateTime value = (DateTime)Convert.ChangeType(dataValue, typeof(DateTime));
if (value.Kind != DateTimeKind.Local)
{
value = value.ToLocalTime();
}
string s = value.ToString("HH:mm:ss\nfff 'ms'");
return s;
}
public override string FormatCursorLabel(IComparable dataValue)
{
// do something
}
If FormatCursorLabel is called the “dataValue” has DateTime.Kind = DateTimeKind.Utc.
If FormatLabel is called the “dataValue” has Datetime.Kind = DateTimeKind.Unspecified. (Although the value is UTC)
How to handle DateTimeKind.Unspecified? Is it Utc or does it depend on what I put into the dataseries?
Hi Uwe,
Thanks for your question. The reason for this issue lies in the very nature of implementation of the DateTime structure. There is certain ambiguity in how conversion methods work with DateTimeKind.Unspecified. You could find detailed explanation in this MSDN article.
Unfortunately, there is nothing we can do about this. The internal representation of DateTime values that we use is DateTime.Ticks, and when restoring a DateTime back from the Ticks value, DateTimeKind is not preserved and set to Unspecified by default.
If you provide DateTimes with DateTimeKind.Local within DataSeries, then you should get local time after such conversion, although DateTimeKind is set to Unspecified. So you could create a new DateTime in your LabelProvider based on the incoming one and set DateTimeKind to Local for it. Then perform conversion to Utc time if necessary.
Hope it helps! Please let us know if you managed to resolve the issue,
Best regards,
Yuriy
Please login first to submit.