This is a migrated thread and some comments may be shown as answers.

TimeSpan on Y Axis

2 Answers 184 Views
Chart (obsolete as of Q1 2013)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
erwin
Top achievements
Rank 1
Veteran
Iron
erwin asked on 14 Nov 2009, 02:10 PM
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.

Regards
Erwin

2 Answers, 1 is accepted

Sort by
0
Giuseppe
Telerik team
answered on 18 Nov 2009, 12:22 PM
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;
    table.Rows.Add(row);
}
 
RadChart1.BeforeLayout += new EventHandler<EventArgs>(RadChart1_BeforeLayout);
RadChart1.DataSource = table;
RadChart1.DataBind();

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,
Manuel
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.
0
Heri .
Top achievements
Rank 1
answered on 25 Mar 2010, 06:26 AM
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"/>
</graph>

I want Result like this (Attach files)

Thanks for your help.

Regards
Heri
Tags
Chart (obsolete as of Q1 2013)
Asked by
erwin
Top achievements
Rank 1
Veteran
Iron
Answers by
Giuseppe
Telerik team
Heri .
Top achievements
Rank 1
Share this question
or