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?
- Uwe Hafner asked 9 years ago
- You must login to post comments
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
- Guest answered 9 years ago
-
I do understand DateTime and the unspecified kind. Thats why I can't make a conversion like this. But it looks like SciChart knows the type. In FormatCursorLabel I get the correct type (utc or local whatever i added). But I get Unspecified in FormatLabel(). So is this by design of SciChart? The one function knows but the other does not? Thanks.
-
It happens completely by chance. The value passed into FormatCursorLabel often comes from hit-test, and during this operation dataValue is being looked for among the actual XValues, therefore no coordinate transformation takes place (there are exceptions though, like when interpolation is used). On the other hand, value incoming into FormatLabel is always converted from a double coordinate, so DateTimeKind is lost.
- You must login to post comments
Please login first to submit.