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

X Axis Datetime display

4 Answers 71 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Chandana
Top achievements
Rank 1
Chandana asked on 18 Dec 2012, 12:41 AM
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

4 Answers, 1 is accepted

Sort by
0
Missing User
answered on 21 Dec 2012, 08:02 AM
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.

0
Chandana
Top achievements
Rank 1
answered on 21 Feb 2013, 05:54 PM
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

0
Accepted
Missing User
answered on 26 Feb 2013, 12:48 PM
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.

0
Chandana
Top achievements
Rank 1
answered on 27 Feb 2013, 12:17 AM
Thank you Ivan.
Tags
Chart
Asked by
Chandana
Top achievements
Rank 1
Answers by
Missing User
Chandana
Top achievements
Rank 1
Share this question
or