Hide most X-Axis Tick Labels

Jonathan

I am trying to figure out how I can control the display of the X-Axis tick labels in the code-behind.
I need to be able to create a graph like the sample attached (custom tick labels) where there are many data points for each label but I only want a label to appear aligned with the first of the data points belonging to that label. Instead I am only able to get what you see in the "too many labels" attached image.

The labels may not be equal step distances apart as seen in the example going from Dec 14th to Dec 17th as data points are not collected on some days so using dates as my tick values doesn't work well.

I have used an XCategory item mapping to add the items for the x-axis.
Then I added a event that is firing and the label points are being set to blank when I step through in debug. However the chart still displays the tick labels anyway when I view it.

Am I making this change in the wrong event or am I changing the wrong property of the tick? What else can I do to make this work?

UPDATE: Just discovered that if I re-run my code to reload the chart the second run takes a relatively long time (over 60 secs to process) and then the tick labels do hide/show as desired. I'm not sure why the second run is so slow and why my labels won't hide the first time through.

Jonathan

Why don't the changes to the labels take effect for me when I can see the changes made in debugging? The labels still appear unmodified in the displayed chart.

I have my code that updates the tick labels immediately after setting the datasource and the labels are defined but then the displayed grid doesn't show my changes. I would appreciate some help with this.

// set the data source with my data

radChart.ItemsSource = dataList;

// now update the labels for each x-axis tickpoint (should hide most of them but shows a select few)

Nikolay

You may try using the LabelStep property to specify that only one of n-number of labels should be displayed. However, in this scenario we would recommend binding your chart to XValue, instead of XCategory and using DateTime values, as categories suggest that each of them is important and cannot be omitted.

In case the issue persists, it would be very helpful for us if you could open a support ticket and send us a sample application demonstrating this behavior, that we can debug locally and provide further support.

Jonathan

Using the LabelStep property I have been able to get labels to show. However while it is working for a particular data sample I'm not sure that it's feasible for all possible data sets I may receive.

I cannot use DateTime values because my data doesn't provide equal time spaced data points for the grid. I have attached a sample of what happens if I go with the DateTime as an XValue. Because data is only captured for certain hours of each day and weekends no data is added, I get large gaps between data points as seen in the "using dates.jpg" attached image.

If I switch back to using xCategory then I have to very carefully manufacture my category values to provide unique values for each one and at the same time set the correct display value for the ones that will show based on the LabelStep. I have been able to pick a step value for the sample data set I have but I cannot guarantee that a nice even step value exists between each set of data points that I want to show a label for. The attached sample "better - need push labels over.jpg" shows the graph the way I want it to display without the gaps where no data is collected between dates. However I would like to see the labels all pushed to the right to prevent the x and y axis labels from colliding as they do and to have the 'D' in "Dec" line up with the gridline that starts that day's data points. (Actually discovered I can add spaces as padding to the beginning of a label to help with this Eg. " Dec 11"

In another sample - "cut off right side.jpg" - when I save the image (which I need to do to share the graph results with another app) the right hand side is cut off and where the label should say Dec 10 it cuts off part of the 1 at the bottom and the entire 0. This does display properly in my test app if I return the results of the chart to a radchart control in the window of the WPF app so the label is there - just cut off when it is saved as an image. Also this sample again shows the x/y axis labels at the bottom left too close to each other and I would like to have the option to move the first x-axis label over to the right and/or hide the first x-axis label entirely in some cases.

All of this to conclude that if I could arbitrarily select which labels I wanted to show or could select the text of the x-axis labels directly for each label, I would have the full customization control I need to
- selectively choose which dates to show (even if they aren't an even number of data points/steps apart)
- not show the first label or last label when we don't want it
- choose to show labels for points farther in to avoid being too close to the graph edges to avoid y-axis label collisions or being cut off

If I could apply the x-axis labels directly for each item then I would simply make the ones I don't want to see to blank or " " and then they would not show. It might be nice if there was a DataPointMember.xAxisLabel type of ItemMapping that would give me this.

Perhaps you can help me solve the above issues based on my descriptions but I think I will also try to put together a sample app I can send you as you suggested as well to see if I can't achieve the full results I need as I think I should be able to if the code that I had previously posted to change the text of each tick label worked.

Nikolay

Thank you for the detailed explanation and the screenshots.On to your questions.

In order to push the X-Axis labels to the right you may either set a few spaces in the label like you have already mentioned , or use a different LayoutMode, so that the first and last labels would be well within the ChartArea.

There are a couple of work-arounds to handle the last label being clipped - you could set a margin on the ChartArea or rotate the labels at a certain degree.

Setting manual axis labels could be achieved with the sample code snippet you've sent, however, please note that you'd have to do it in a LayoutUpdated event like this :

This is also how you may set empty strings for specific labels, such as the first or the last one if needed, however, a better approach for this would be to use a Style and a Visibility Converter. Here is a sample :

In order to completely control the labels I am using both the LayoutUpdated event and the LabelConverter. The event sets the custom label text on each required label and the LabelConverter hides all the other labels that I don't want to see.

I moved away from the use of the XCategory and am instead using the XValues and assigning incremental values to each data-point. This allows me to draw gridlines accurately and assign the labels accurately as well.

The following is my code that runs with the LayoutUpdated event.
I changed it from what I had started with because it had been taking 30+ seconds to generate the chart the old way. As it is below now it takes only 2 -3 seconds. Instead of iterating through all the tickpoints I now only need to hit the ones that have custom labels that are visible. All the rest are made invisible by the LabelConverter code.

It uses a Step value because I've found for data sets where I can use a step because the labels are evenly spaced get better performance when setting the xAxis Step value.

The end result is that I can now create graphs with custom labels where the text of the labels may not be unique. See attached sample graph image.

I do wonder if it is possible to create a binding to a converter for the text of the labels. That might be a nice solution that wouldn't require modifying the labels in another event as I have done and I suspect would give better performance since the LabelConverter that hides/shows the labels seems to run very well. I don't have enough WPF experience or knowledge to know how to even try that though.

Jonathan

I have gone back to using the XCategory and assigning my labels that way as I found using the LayoutUpdated event would add 2 - 3 seconds of processing time to the generation of the charts with about a dozen visible labels or less. The more visible labels the longer it took. By going with the XCategory I don't need the LayoutUpdated event to update the labels and the ValueConverter makes the appropriate labels visible. By making this change now my graphs usually generate in about 1 second or less.

Actually the LayoutUpdated event seems to be called repeatedly. If you find you want to go that way I suggest the SizeChanged event which for me was fired only once when creating the chart. (I create the chart completely in the code-behind and I save it as an image and I'm done with it.)

Nikolay

For performance reasons the better solution in your scenario seems to be the one you've described in your last post - using a ValueConverter for the labels visibility and XCategory, without the need to update them through the LayoutUpdated event, which is indeed called repeatedly.

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.