Jump to content
Software FX Community

DataUnit.DoubleToDate() throws error when converting Ticks


brett.burkhart

Recommended Posts

I'm trying to bind my X points to a DateTime.Ticks value, but I keeping getting an error from ChartFX saying the Ticks must be between the Min and Max tick value.  Before I get into the object binding, let me show a quick example that fails.

DateTime dateTime = DataUnit.DoubleToDate(DateTime.Now.Ticks);<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.

Parameter name: ticks

 

Now for my real world exmaple: 

We have a generic interface for all our Points, it defines both decimal X and decimal Y properties.  One object wants to display DateTime in the X axis, so its interface implementation returns the DateTime.Ticks value.

public decimal X

{

  get { return this.DateTime.Ticks; }

}

public decimal Y

{

  get { return this.CrossingRate; }

}

<cfx:Chart.AxisX>

 <cfx:Axis>

<cfx:Axis.DataFormat>

 <cfx:ValueFormat Format="Time" />

</cfx:Axis.DataFormat>

<cfx:Axis.Labels>

 <cfx:AxisLabelAttributes Format="Time" />

</cfx:Axis.Labels>

 </cfx:Axis>

</cfx:Chart.AxisX>

This throws an error, the same error as above.  If you change the object to return the DateTime itself, and not ticks, it works fine.

public DateTime X

{

  get { return this.DateTime; }

}

 

post-5684-13922409693129_thumb.jpg

Link to comment
Share on other sites

The purpose of DataUnit.DoubleToDate is not to convert from Ticks to Dates but to be an opposite function to DataUnit.DateToDouble. Internally our code uses doubles so when we see a date we call DateToDouble. If you try to assign a value we've processed to a double you might need DoubleToDate.

Note that most of our API returns a DataUnit (e.g. Axis.Min, Axis.Max, etc.) and we provide automatic casts between DateTime and doubles so you should not need the DataUnit static functions often.

When we made this change we actually started using Ticks but because of their resolution it causes loss of precision on certain dates so internally we now divide Ticks by 10000, this still gives us millisecond accuracy without the loss of precision. Obviously this is an implementation detail that you should not code against.

We'd rather leave our API agnostic of how dates are internally converted so I wonder if you can bind to the DateTime property instead of X.

Regards,

JuanC

Link to comment
Share on other sites

So, I'm still not convinced why this code does not work.

public decimal X

{

  get { return this.DateTime.Ticks; }

}

public decimal Y

{

  get { return this.CrossingRate; }

}

<cfx:Chart.AxisX>

 <cfx:Axis>

<cfx:Axis.DataFormat>

 <cfx:ValueFormat Format="Time" />

</cfx:Axis.DataFormat>

<cfx:Axis.Labels>

 <cfx:AxisLabelAttributes Format="Time" />

</cfx:Axis.Labels>

 </cfx:Axis>

</cfx:Chart.AxisX>

As a GUI developer, I might not have control over what the X value return is, so I can't just return a DateTime.  It returns Ticks.  But for some reason, when I try to set the ValueFormat and the Label format to "Time", I get an internal ChartFX error saying the Ticks value (my data value), is outside the bounds of the Min/Max ticks.  I have a DateTime.Ticks...I need to bind the format to Time.  I get an error.

Link to comment
Share on other sites

The reason why DateTime.Ticks does not work is the same as why the following also does not work

public double X2{   get { return this.DateTime.ToFileTime(); }}

public double X3{   get { return this.DateTime.ToOADate(); }}

In all these 3 cases you are using arbitrary functions/properties that translate between a datetime and a number and it would be impossible for us to know which one you are using. Because of this it makes more sense for us to handle dates (DateTime).

JuanC

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...