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

DateTimeContinuousAxis, show another label instead x datetime values

1 Answer 147 Views
Chart
This is a migrated thread and some comments may be shown as answers.
malabareand
Top achievements
Rank 1
malabareand asked on 14 Oct 2014, 08:22 PM
Hello everyone!  

Im drawing a chart with RadCartesianCharts, and i have to display another value (age) instead custom x value datetime 

the structure for each point series is:

HeightPerson
{
  DateTime DateMeasure { get: set; }
  decimal    Height  { get: set; }
  decimal    Age  { get: set; }
}


and i'm using the following  horizontalAxis configuration:

<telerik:RadCartesianChart.HorizontalAxis>
  <chartView:DateTimeContinuousAxis LabelFitMode="Rotate"
                      LabelFormat="{Binding AxisXformat}"
                      Visibility="{Binding VisibilityAxis}"
                      Title="{Binding TitleX}" />
</telerik:RadCartesianChart.HorizontalAxis>



 and the code where i'm making series


var edadSeries = new LineSeries(){
              ItemsSource = vm.PersonAge,
              Visibility = System.Windows.Visibility.Visible,
             //here is where i'm binding the date, but i would like to bind the "Age" property
             //AnotherCategoryBinding = new PropertyNameDataPointBinding() { PropertyName = "Age" },
             CategoryBinding = new PropertyNameDataPointBinding() { PropertyName = "DateMeasure" },
             ValueBinding = new PropertyNameDataPointBinding() { PropertyName = "Height" },
             BorderBrush = System.Windows.Media.Brushes.Black,
             BorderThickness = new Thickness(1),
};

another solution, could be show only x (datetime) values for datapoint in x axis for try to cheat in another way

regards

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 17 Oct 2014, 11:11 AM
Hi Carlos,

Keep in mind that the labels of the Cartesian chart's axes are not related with the data points that are plotted on the chart. Which means that you cannot get directly the Age property from your view models and use it in the label. 

If you want to show decimal values (in your case, Age) you can consider using another type of axis. For example, a LinearAxis and ScatterLineSeries.

Another approach you can try is to define a LabelTemplate for the DateTimeContinuousAxis and use an IValueConverter in the text's binding to convert the DateTime string in the label to a specific decimal value.

<telerik:LinearAxis/>
    <telerik:LinearAxis.LabelTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Converter={StaticResource DateStringToAgeConverter}}" />
        </DataTemplate>
    </telerik:LinearAxis.LabelTemplate>
<telerik:LinearAxis>

You can also try to implement custom labels with chart's annotations. Basically, you can hide the axis and then use CartesianCustomAnnotation with a Rectangle (for the ticks) and TextBlock (for the labels) in its ContentTemplate.

Please let me know if you need any further assistance.

Regards,
Martin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Chart
Asked by
malabareand
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or