Jump to content
Software FX Community

What is the type of AxisFormat.Time?


jamescway

Recommended Posts

I have a DataTable with a Time column. What format or type should I make this column?

I tried playing with using the DateTime type which does work, but the date is stored as well in the form of (1/1/1001 hh:mm:ss) which I don't want, just the time.

I saw that there was a an AxisFormat.Time and AxisFormat.DateTime. What is the difference between these two types and how do you use the AxisFormat.Time with a datasource? I tried to find the answer on the forums, but was unable to.

I also tried to create the column as a DateTime, and pass the time using ToOATime(). On the chart I set it up this way:

_chartCtrl.AxisX.LabelsFormat.Format = AxisFormat.Time;

_chartCtrl.AxisX.LabelsFormat.CustomFormat = "mm:ss";

But instead of showing mm:ss it doesn't seem to recognize the passed value and just prints out the double value of the OATime.

Thanks,

James

Link to comment
Share on other sites

 Following is a sample showing how to accomplish what you want. It loads Y (values) and X (date time) data and then it sets the format of the X-Axis to show minutes and seconds.Additionally,  are the differences between Date/Time Axis Formats: - AxisFormat.Time = shows time labels.- AxisFormat.Date = shows date labels.- AxisFormat.DateTime = shows both date and time labelsprivate void DateAxisX_Load(object sender, EventArgs e)   {   chart1.Data.Series = 3;   chart1.Data.Points = 5;   Random ran = new Random();   DateTime mydate = DateTime.Now;   //Loads Chart FX data   for (int j = 0; j < chart1.Data.Points; j++)   {   for (int i = 0; i < chart1.Data.Series; i++)   {   chart1.Data.Y[i, j] = ran.NextDouble() * 100;   chart1.Data.X[i, j] = mydate.ToOADate();   }   mydate = mydate.AddMinutes(ran.Next(7, 23));   }   chart1.LegendBox.Visible = false;   chart1.AxisX.AutoScroll = true;   chart1.AxisX.PixelsPerUnit = 1000;   //Axis Labels format   chart1.AxisX.LabelsFormat.Format = AxisFormat.Time;   chart1.AxisX.LabelsFormat.CustomFormat = "hh:mm tt";   chart1.AxisX.Step = 1 / 60;   }

Regards RB

Link to comment
Share on other sites

Thanks for the reply Rogelio!

This is actually very similar to the method that I ended up figuring out except I am using a datasource for the chart (DataTable). I was forced to make one of the columns a DateTime which works fine using the custom format "hh:mm:ss". The problem is that when I save this datatable it saves the entire date time 2009-03-04T00:00:00-08:00 when all I really need is just the time. I was hoping I could pass just a string or something instead that AxisFormat.Time will be able to understand, but I wasn't able to figure that out.

Maybe I can use some type of xmlwriter function to save it, but I haven't figured out how to do that either.

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...