X Axis Datetime display

5 posts, 1 answers
  1. Chandana
    Chandana avatar
    13 posts
    Member since:
    Apr 2011

    Posted 17 Dec 2012 Link to this post

    Hi,

    1. I have a databound radchart which displays time on the X-Axis. The data is in 30 minute intervals (Ex: 6:30:00,7:30:00, 8:30:00 etc). Can I make the radchart display 7:00:00, 8:00:00, 9:00:00 etc on the X Axis even though I have no data points at these timings?

    2. Also, Can I format it to display "6:30 AM"?
    I tried rchart.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "h:mm tt", it doesn't work.

    Appreciate any help on this. Thank you.

    Regards,
    Chandana
  2. Missing user
    Missing user avatar

    Posted 21 Dec 2012 Link to this post

    Hello Chandana,

    You can change the X axis' settings by subscribing to the RadCharts' DataBound event:
    this.RadChart1.DataBound += new EventHandler<Telerik.Windows.Controls.Charting.ChartDataBoundEventArgs>(RadChart1_DataBound);
    and then add the following code:
    void RadChart1_DataBound(object sender, Telerik.Windows.Controls.Charting.ChartDataBoundEventArgs e)
    {
        var series = this.RadChart1.DefaultView.ChartArea.DataSeries[0];
        double oneHour = 1 / 24d;
        double startTime = series[0].XValue;
        double endTime = series[series.Count - 1].XValue;
        this.RadChart1.DefaultView.ChartArea.AxisX.MinValue = (startTime - (startTime % oneHour));
        this.RadChart1.DefaultView.ChartArea.AxisX.MaxValue = (endTime - (endTime % oneHour) + oneHour);
        this.RadChart1.DefaultView.ChartArea.AxisX.Step = oneHour;
        this.RadChart1.DefaultView.ChartArea.AxisX.AutoRange = false;
    }

    As for the second part of your post, you should try setting the application's culture to the invariant culture,e.g.:
    System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
    This is because of the default behavior of the .NET framework - the "tt" part of the format string will not result in the AM/PM sign being shown, unless the current application culture supports it.

    All the best,
    Ivan N.
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Chandana
    Chandana avatar
    13 posts
    Member since:
    Apr 2011

    Posted 21 Feb 2013 Link to this post

    Hi,

    I set the culture but still when I write,

    vChart.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "h:mm tt", it jsut displays "h:mm tt" instead of the time.
    My XAxis values are in double format (6,6.5,7 etc and I want to display 6:00 AM,6:30 AM,7:00 AM etc).


    Thank you.
    Regards,
    Chandana

  5. Answer
    Missing user
    Missing user avatar

    Posted 26 Feb 2013 Link to this post

    Hi Chandana,

    I'm sorry for misunderstanding you. I assumed your business objects used DateTime for X-Axis item mapping. Allow me to clarify the formatting behavior of RadChart: RadChart uses methods native to the .NET framework to format values. That being said, the .NET framework doesn't support DateTime formatting of non-DateTime values. I.e. the "h:mm tt" format string will only have effect with DateTime objects, since they are the only ones that take such a format string as a parameter. Therefore, it is normal that a DateTime format string has no effect on double values.

    Fortunately, RadChart can convert double values to DateTime, as long as they can be interpreted as OLE Automation Dates. You only have to set the RadChart.DefaultView.ChartArea.AxisX.IsDateTime property to true. Should you be unfamiliar with the subject on OA Dates, you can check out this MSDN page.

    For your convenience, I have attached a small project that demonstrates how to make RadChart work with double values for the X-Axis and display them as a date in the format you wanted.

    Regards,
    Ivan N.
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Chandana
    Chandana avatar
    13 posts
    Member since:
    Apr 2011

    Posted 26 Feb 2013 Link to this post

    Thank you Ivan.
Back to Top
DevCraft banner