3

I'm trying to get a duration on one of my axis's (the X-axis). Currently I use a date axis, though this can't have a day 0. I currently have: Dates

As you can see, I don't have a day 0, which I need, since something could have happened on day 0 (well, less than 24-hours from the start.) What I need is something formatted as: numberOfDays hours:minutes:seconds

I currently use the following code to calculate my x:

XDate date = new XDate(0, 0,
    event.Time.Days,
    event.Time.Hours,
    event.Time.Minutes,
    event.Time.Seconds,
    event.Time.Milliseconds);
double x = date;

And my axis:

graphPane.XAxis.Title.Text = xAxisTitleText.ToString();
graphPane.XAxis.Scale.IsVisible = true;
graphPane.XAxis.Type = AxisType.Date;
graphPane.XAxis.Scale.Format = "dd HH:mm:ss";

So ultimately I want tags like: 0 02:23:14 0 08:56:12 1 01:03:44

I need to be able to zoom out and see the days and hours, but also zoom in and see each event's minutes and seconds.

Note: It would be awesome if negative numbers could be hidden, though isn't very important.

Thanks!

The Oddler
  • 6,314
  • 7
  • 51
  • 94

1 Answers1

6

I fixed my problem myself!

Here's how I did it, for those who might be looking for something similar in the future:

First I now set the x-value of my point to the TotalHours of my TimeSpan, then I added a handler to the XAxis.ScaleFormatEvent

graphPane.XAxis.ScaleFormatEvent += new Axis.ScaleFormatHandler(Axis_ScaleFormatEvent);

static string Axis_ScaleFormatEvent(GraphPane pane, Axis axis, double val, int index)
{
    TimeSpan timeVal = TimeSpan.FromHours(val); return timeVal.ToString();
}

Hope this helps other's looking for the same thing!

Note: With this method it's also possible to do other stuff, anything you can change to a double, and then change back should work here. Very useful stuff.

The Oddler
  • 6,314
  • 7
  • 51
  • 94