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

[Solved] Set DateTimeCategoricalAxis in behind code

12 Answers 225 Views
Chart for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Alfred
Top achievements
Rank 1
Alfred asked on 02 May 2013, 10:09 PM
Hello.
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

Sort by
0
Ivaylo Gergov
Telerik team
answered on 03 May 2013, 10:13 AM
Hi Alfred,

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
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Alfred
Top achievements
Rank 1
answered on 03 May 2013, 12:12 PM
This was very helpful. 

Thank you very much.

Al
0
Alfred
Top achievements
Rank 1
answered on 18 Jun 2013, 03:36 PM

 

How would I do the same for DateTimeContinuousAxis?
Thanks,
Al

0
Rosy Topchiyska
Telerik team
answered on 19 Jun 2013, 01:32 PM
Hello Alfred,

Thank 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.


Regards,
Rositsa Topchiyska
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Alfred
Top achievements
Rank 1
answered on 19 Jun 2013, 02:12 PM
I am attempting to use the Pan and Zoom feature.  It appears that the Zoom setting are only available with the date continuous axis.  All charts are built dynamically in my application.

Thanks,
Al
0
Rosy Topchiyska
Telerik team
answered on 20 Jun 2013, 02:29 PM
Hi Alfred,

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
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Alfred
Top achievements
Rank 1
answered on 20 Jun 2013, 06:36 PM
Thank you.  That was very helpful.  Is there a way to limit the number of dates that initially show on the axis like you can with DateTimeContinuousAxis with MaximumTicks?  I would like the dates to be readable without overlapping, and then pan to see additional dates on the axis.
Thanks,
Al
0
Rosy Topchiyska
Telerik team
answered on 21 Jun 2013, 03:03 PM
Hello Alfred,

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.


Regards,
Rositsa Topchiyska
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Alfred
Top achievements
Rank 1
answered on 21 Jun 2013, 03:47 PM
Rositsa;

I don't understand your suggestion.  Can you provide a little more detail?

Thanks,
Al
0
Giuseppe
Telerik team
answered on 21 Jun 2013, 04:14 PM
Hello Alfred,

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
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
kaliprasad
Top achievements
Rank 1
answered on 20 Mar 2017, 11:09 AM

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

0
Pavel R. Pavlov
Telerik team
answered on 23 Mar 2017, 07:32 AM
Hello,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Chart for XAML
Asked by
Alfred
Top achievements
Rank 1
Answers by
Ivaylo Gergov
Telerik team
Alfred
Top achievements
Rank 1
Rosy Topchiyska
Telerik team
Giuseppe
Telerik team
kaliprasad
Top achievements
Rank 1
Pavel R. Pavlov
Telerik team
Share this question
or