locked
How do I use ChartValueType.Time on the XAxis of a line chart?

    Question

  • Hi

    I'm trying to draw a FastLine graph where the points are all really (TimeSpan timeSinceStart,  double value).

    Because the graph won't bind to TimeSpan I've used DateTime instead - with all x values relative to DateTime(1900,1,1)  - is this the correct thing to do?

    However, when I plot the series it refuses to put "sensible" values in for the Minimum on the XAxis - how should this be setup? I've also tried using IsStartedFromZero - is this any use?

    Some snippets of my code (if that helps)


                ChartArea area = new ChartArea(chartAreaName);
                area.AxisX.IsLabelAutoFit = false;
                //area.AxisX.IsStartedFromZero = true;
                //area.AxisX.Minimum = 0.0;
                //area.AxisX.Minimum = ChartPoint.BaseTime.;
                area.AxisX.LabelStyle.Format = "hh:mm:ss"; //"N0";
                area.AxisX.IntervalType = DateTimeIntervalType.Hours;
                area.AxisY.IsLabelAutoFit = false;
                Chart1.ChartAreas.Add(area);

                Series speedSeries = new Series(chartName);
                speedSeries.Points.DataBind(items, xProperty, yProperty, string.Empty);
                speedSeries.ChartType = SeriesChartType.FastLine;
                speedSeries.ChartArea = chartAreaName;
                speedSeries.XValueType = ChartValueType.Time;
                Chart1.Series.Add(speedSeries);


    Stuart
    Tuesday, December 16, 2008 10:17 AM

Answers

  • I setup the x-axis like this:

    chart.ChartAreas[0].AxisX.LabelStyle.IntervalType = DateTimeIntervalType.Seconds;
    chart.ChartAreas[0].AxisX.LabelStyle.Format =
    "T";

    which shows in long time format (eg 10:44:32)

    and when assigning values to the points I use DateTime.ToOADate() for the x value

    Hope that helps a little

    Tuesday, December 16, 2008 10:43 AM
  • Thanks Jim - perfect :) - I'm now using:

                area.AxisX.Minimum = ChartPoint.BaseTime.ToOADate();
                area.AxisX.LabelStyle.Format = "HH:mm:ss";

    (And a little bit of me also like that fact I'm still using OLE, even if it is just for these dates...)

    Stuart
    • Marked as answer by StuartLodge Tuesday, December 16, 2008 11:34 AM
    Tuesday, December 16, 2008 11:34 AM

All replies

  • I setup the x-axis like this:

    chart.ChartAreas[0].AxisX.LabelStyle.IntervalType = DateTimeIntervalType.Seconds;
    chart.ChartAreas[0].AxisX.LabelStyle.Format =
    "T";

    which shows in long time format (eg 10:44:32)

    and when assigning values to the points I use DateTime.ToOADate() for the x value

    Hope that helps a little

    Tuesday, December 16, 2008 10:43 AM
  • Thanks Jim - perfect :) - I'm now using:

                area.AxisX.Minimum = ChartPoint.BaseTime.ToOADate();
                area.AxisX.LabelStyle.Format = "HH:mm:ss";

    (And a little bit of me also like that fact I'm still using OLE, even if it is just for these dates...)

    Stuart
    • Marked as answer by StuartLodge Tuesday, December 16, 2008 11:34 AM
    Tuesday, December 16, 2008 11:34 AM
  • i have small doubt if time is more than 24 hours how can i able to show in yaxis values any body tell me plzzzzzzzzzz
    kiran
    Thursday, May 07, 2009 4:33 AM