TimeSpan on Y Axis

3 posts, 0 answers
  1. erwin
    erwin avatar
    358 posts
    Member since:
    Dec 2006

    Posted 14 Nov 2009 Link to this post

    On my Chart I have a Timespan on the Y Axis. So far I managed to use Integer TotalMintues, however, I'd like to Format it
    hh:mm for better readability.
    Thanks for your help.

  2. Giuseppe
    Giuseppe avatar
    2363 posts

    Posted 18 Nov 2009 Link to this post

    Hi erwin,

    RadChart does not provide support out-of-the-box for this scenario but you can handle the BeforeLayout event and format the axis item labels manually:

    Chart Initialization
    DataTable table = new DataTable();
    table.Columns.Add("Value", typeof(double));
    Random random = new Random((int)DateTime.Now.Ticks);
    for (int i = 0; i < 10; i++)
        DataRow row = table.NewRow();
        row["Value"] = TimeSpan.FromMinutes(random.Next(10, 240)).TotalMinutes;
    RadChart1.BeforeLayout += new EventHandler<EventArgs>(RadChart1_BeforeLayout);
    RadChart1.DataSource = table;

    BeforeLayout handler:
    private void RadChart1_BeforeLayout(object sender, EventArgs e)
        foreach (ChartAxisItem axisItem in RadChart1.PlotArea.YAxis.Items)
            TimeSpan timeSpan = TimeSpan.FromMinutes(Int32.Parse(axisItem.TextBlock.Text));
            axisItem.TextBlock.Text = new DateTime(timeSpan.Ticks).ToString("hh:mm");

    Hope this helps.

    Kind regards,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. Heri .
    Heri . avatar
    29 posts
    Member since:
    Mar 2010

    Posted 25 Mar 2010 Link to this post

    I'm create WEB and my web include Chart.
    On my Chart I have a Time on the Y Axis. How to display Chart.
    This my data in XML format.

    <graph >
    <Set Time="08:10" value="5"/>
    <Set Time="08:20" value="15"/>
    <Set Time="08:30" value="10"/>
    <Set Time="08:40" value="30"/>
    <Set Time="08:50" value="20"/>

    I want Result like this (Attach files)

    Thanks for your help.

Back to Top