DateTimeContinuousAxis, show another label instead x datetime values

2 posts, 0 answers
  1. malabareand
    malabareand avatar
    2 posts
    Member since:
    Mar 2012

    Posted 14 Oct 2014 Link to this post

    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
  2. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 17 Oct 2014 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top