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

how to change display of AxisLabels on DateTimeContinuousAxis

3 Answers 75 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Doug
Top achievements
Rank 1
Doug asked on 04 Nov 2016, 12:20 PM
I have a RadCartesianChart with a DateTimeContinuousAxis on the HorizontalAxis.  The data graphs exactly the way I want it, however I would like to display the way the horizontal AxisLabels display.  I would like them to display the total elapsed seconds from the minimum X value.  Is there some kind of template I could override?

3 Answers, 1 is accepted

Sort by
0
Accepted
Lance | Manager Technical Support
Telerik team
answered on 04 Nov 2016, 06:40 PM
Hi Doug,

You can indeed set a custom template for the Axis's label template, here's an example:

<telerik:RadCartesianChart.HorizontalAxis>
                <telerik:DateTimeContinuousAxis LabelFitMode="MultiLine" LabelFormat="MMM yyyy">
                    <telerik:DateTimeContinuousAxis.LabelTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding}"/>
                        </DataTemplate>
                    </telerik:DateTimeContinuousAxis.LabelTemplate>
                </telerik:DateTimeContinuousAxis>
</telerik:RadCartesianChart.HorizontalAxis>


Here's a screenshot of the chart using the template above.

One thing to be aware of is that the DataContext of the label template is the display value for that label (of type string). If you want to display something different, you could use a value converter and pass other relevant information in the converter parameter.

Regards,
Lance | Tech Support Engineer, Sr.
Telerik by Progress
Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
0
Doug
Top achievements
Rank 1
answered on 07 Nov 2016, 01:00 PM

Lance, That worked perfectly.  I created a Converter from IValueConverter and changed the DateTime data to a Timespan object using a predefined epoch DateTime object.  I then returned the TotalSeconds from the epoch.

public class TimespanDataConverter : IValueConverter
  {
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
     {
       if (value is DateTime)
       {
         TimeSpan xVal = (DateTime)value - MainWindow._epoch;
         return Math.Round(xVal.TotalSeconds);
       }
       return value.ToString();
     }
     public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
     {
       throw new NotImplementedException();
     }
   }
}

 

0
Lance | Manager Technical Support
Telerik team
answered on 07 Nov 2016, 05:46 PM
Hi Doug,

I'm happy to hear that the template approach worked for you and thank you for sharing your solution with the community.

Please let us know if you have any further questions (note: since you have a current license, you can also use the Support Ticket system).

Regards,
Lance | Tech Support Engineer, Sr.
Telerik by Progress
Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
Tags
Chart
Asked by
Doug
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Doug
Top achievements
Rank 1
Share this question
or