AxisX ItemLabel AutoRange Match DataPoints

9 posts, 0 answers
  1. Aaron
    Aaron avatar
    14 posts
    Member since:
    Feb 2012

    Posted 11 Apr 2012 Link to this post

    When the AxisX is displaying a Date and AutoRange is True, the ItemLabels that are displayed do not match/align with the DataPoints.  An example image is attached.  It is fine that some DataPoints do not have ItemLabels on the AxisX, but I would like the ItemLabels that are displayed to at least match up with a DataPoint.

    This is the data source for the attached image:
    Date Value
    9/11/2011 72.2213
    9/18/2011 69.19848
    9/25/2011 68.97124
    10/2/2011 70.24254
    10/9/2011 73.49885
    10/16/2011 74.02531
    10/23/2011 73.55423
    10/30/2011 74.57479
    11/6/2011 74.59043
    11/13/2011 73.31678
    11/20/2011 73.33056
    11/27/2011 76.07927
    12/4/2011 72.5183

    Current ItemLabel Value Desired Value (actually in DataSet above)
    10/01/2011 10/02/2011
    10/21/2011 10/23/2011
    11/10/2011 11/13/2011
    11/30/2011 12/04/2011


    Is there a way to force the AxisX ItemLabels to only display values for actual DataPoints in the DataSet?

  2. Nikolay
    Admin
    Nikolay avatar
    385 posts

    Posted 12 Apr 2012 Link to this post

    Hello Aaron,

    The axis AutoRange spaces the labels, depending on the available space - if you do not have enough space for, say, 10 labels but you have 10 Data Points, then it would not be possible to match each point with a label, unless you treat them as categories. Thus, the simplest solution for your scenario would be to map the DateTime values to XCategory, instead of XValue :
    seriesMapping.ItemMappings.Add(new ItemMapping("Date", DataPointMember.XCategory));

    This way you would have one label for each data point at all times.Hope this helps.

    All the best,
    Nikolay
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. DevCraft banner
  4. Aaron
    Aaron avatar
    14 posts
    Member since:
    Feb 2012

    Posted 13 Apr 2012 Link to this post

    Thank you for your response.

    Would each DataPoint still be part of the same LineSeries (will each point be connected via a line from one to the other)?

    Is it possible to "autorange" display the categories?  Ex: If I have 800 points, I don't want 800 ItemLabels.


    If the "autorange" ability does not exist.  Is it possible to conditionally display categories labels?

  5. Nikolay
    Admin
    Nikolay avatar
    385 posts

    Posted 18 Apr 2012 Link to this post

    Hello Aaron,

    Yes, each DataPoint would be a part of the same Line series, the only difference is that when using categories the chart treats data as a sequence of non-numerical text labels. You couldn't sample the data down as each point is important, however, when you have a large data set and you do not wish to display all of the labels you could use the LabelStep property, which displays 1 from X number of labels :
    RadChart1.DefaultView.ChartArea.AxisX.LabelStep = 10;

    This way if you have, say 100 DataPoints, you would only have 10 labels, so you could avoid overlapping of the text. Alternatively, you could always use the manual axis range when needed.

    Kind regards,
    Nikolay
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  6. Aaron
    Aaron avatar
    14 posts
    Member since:
    Feb 2012

    Posted 18 Apr 2012 Link to this post

    Thank you, using XCategory in conjunction with LabelStep is working well.  Now the only issue I'm having is that too many Major Tick Marks are visible, when the Label is not displayed the Major Tick Mark still is (image attached).

    I tried setting the AxisX AutoRange to false and calculating the "Step" manually but I am having difficulty getting anything to display.  I believe this may be due to the XCategory being used instead of XValue.

    I have thought of two solutions:
    1.  Include the Major Tick Mark in the Label somehow.
    2. Continue down the path of manually calculating the AxisX Step value.


    What would you recommend?  Do you have any documentation around calculating the AxisX manually when an XCategory is being used?
  7. Aaron
    Aaron avatar
    14 posts
    Member since:
    Feb 2012

    Posted 16 May 2012 Link to this post

    Petar Marchev,

    I attempted to use the AxisX AddRange method, but now the values being displayed in the ItemLabels do not match the Point Marks they should be associated with (image attached).  The date range for the attached image should be 09/11/2011 through 12/04/2011.  I used the values AxisX.AddRange(1, 14, 2) and now, the last ItemLabel is displaying 10/23/2011 instead of 12/04/2011.

    The AxisX is only displaying a tick and label for every other PointMark, but it is displaying values in the ItemLabels in order as if it was not skipping any PointMarks.
  8. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 21 May 2012 Link to this post

    Hi Aaron,

    It seems that the suggestion I made in my previous post is not applicable as it results in an incorrect chart. I apologize for this.

    The only suggestion that I can make is to attach a handler to the SizeChanged event of the chart, find the ticks from the visual tree and hide them. I have prepared a simple project that demonstrates this and attached it to this post. Please explore it and let us know if this suggestion is a feasible solution for your current project.

    Regards,
    Petar Marchev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  9. Aaron
    Aaron avatar
    14 posts
    Member since:
    Feb 2012

    Posted 03 Aug 2012 Link to this post

    Petar Marchev,

    When I run the solution you provided the output is what I'm looking for.  However, this solution does not work in my case.  The SizeChanged event is not raised for my chart consistently.  I am not binding to my chart a single time, the ItemsSource for my chart can be updated, the number of DataPoints can change, but the size of the chart will not change.

    I have attempted to execute this code from the DataBound event, but the call to ChildrenOfTypeExtensions.ChildrenOfType<AxisXItem2D>(); does not return any results.

    I have also attempted to execute this code in-line after the ItemsSource has been updated, but again the ChildrenOfTypeExtensions.ChildrenOfType<AxisXItem2D>(); does not return any results.

    Why does this code only seem to work in the Chart's SizeChanged event?  Is there a way to get this to work in the Chart's DataBound event or the AxisX's RangeChanged event?  Is there a way to get this to work if executed manually/in-line after the ItemsSource is updated?
  10. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 06 Aug 2012 Link to this post

    Hi Aaron,

    I have attached a demo project to demonstrate how you can achieve this. The same code (the code from my previous attachment, that hides the ticks) is used but in the LayoutUpdated event. We unsubscribe from the LayoutUpdated event as soon as we have hidden the ticks we do not need. This is done in order to avoid a layout exception and performance consideration (this event is being raised many times, and we do not want to do the same thing over and over again).

    It is possible that this code (the HideBetweenTicks method) is executed before the ticks have been generated. This is the reason you were not able to find this panel.

    Check out the project and see if you can adopt this to your app.

    All the best,
    Petar Marchev
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
DevCraft banner