Is it possible to set the DateTimeComponent and the LabelFormat of the DateTimeCategoricalAxis in C#. I have looked at the documentation, but I was unable to locate anything that addressed my specific requirement.
Thank you.
Al
12 Answers, 1 is accepted
Thank you for using our RadControls for Windows 8.
Yes, it is possible to set the DateTimeCategoricalAxis.DateTimeComponent and the DateTimeCategoricalAxis.LabelFormat properties in C# like this:
(this.chart.HorizontalAxis as DateTimeCategoricalAxis).DateTimeComponent = Telerik.Charting.DateTimeComponent.Year;(this.chart.HorizontalAxis as DateTimeCategoricalAxis).LabelFormat = "{0:yyyy}";I hope this helps. Let me know if you need further assistance.
Regards,
Ivaylo Gergov
the Telerik team
Thank you very much.
Al
How would I do the same for DateTimeContinuousAxis?
Thanks,
AlThank you for your question.
The DateTimeContinuousAxis does not expose DateTimeComponent property and it works in a different way: here is an article in our online documentation where all the properties of DateTimeContinuousAxis are listed and also the differences between the DateTimeContinuous and DateTimeCategoricalAxis. Could you elaborate what is your specific scenario that cannot be accommodated by DateTimeCategoricalAxis (with DateTimeComponent) that you are trying to solve with DateTimeContinuousAxis?
And this is how you set the LabelFormat:
(this.chart.HorizontalAxis as DateTimeContinuousAxis).LabelFormat = "{0:yyyy}";I hope this was useful and don’t hesitate to contact us again if you have any other questions or ideas.
Rositsa Topchiyska
Telerik
Thanks,
Al
I have prepared a sample project with RadCartesianChart that uses DateTimeCategoricalAxis for HorizontalAxis and pan and zoom behavior enabled. Could you check if this works, and if it does, please modify it in order to reproduce the issue.
Let me know how it goes.
Regards,Rositsa Topchiyska
Telerik
Thanks,
Al
Thank you for your question.
I can suggest you bind the RadChart.Zoom property to a property from your view model. When the PropertyChanged event of your view model is raised you can update the MajorTicksInterval property of the DateTimeCategoricalAxis depending on the zoom value (again, you need to bind this one to a property from your view model).
I hope this was helpful.
Rositsa Topchiyska
Telerik
I don't understand your suggestion. Can you provide a little more detail?
Thanks,
Al
Sorry for misleading you a bit with our previous reply -- currently DateTimeCategoricalAxis.MajorTickInterval is not a dependency property so it cannot be set through binding expression from the view model. We will address this limitation for the official public build next week and meanwhile you can use a similar approach but set the axis property directly in code-behind (see the attached sample application).
Hope this helps.
Regards,
Giuseppe
Telerik
Hi Ivaylo,
I want to use a converter in place of "{0:yyyy}" // some converter.
The converter will be
public class AxisLabelConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string label = "{0} H";
var date = System.Convert.ToDateTime(value) - new DateTime();
label = string.Format(label, date.TotalHours.ToString("0.##"));
}
}
I have the solution in the XAML but need the same in code behind.
<telerik:RadCartesianChart.HorizontalAxis>
<telerik:DateTimeContinuousAxis x:Name="MultiAxis" LabelTemplate="{StaticResource axisLabelTemplate}" Title="Timestamp (h)" LabelFitMode="Rotate" />
</telerik:RadCartesianChart.HorizontalAxis>
Thanks
kaliprasad
In order to implement the binding in code you will need to create the DataTimeContinuiesAxis in code and set its properties per your needs. After that you can set the HorizontalAxis property of the chart. Have you tried this approach? Are you saying that this is not possible? Please give it a try and let us know how it goes on your side.
Regards,
Pavel R. Pavlov
Telerik by Progress