Hello!
I have 2 questions on the DataChart labels and axis.
1. How does LabelSettings.Extent for the NumericXAxis work? I am using the trick to format the labels using the DataTempate with the TextBlock and Converter. I set the extent to some specific value, like 45, but instead of spanning 45 pixels, it starts creating empty space underneath, so there is a big margin at the bottom of the chart. Sometimes it does make the next labels go to the 2nd and 3rd line, like this:
label1 label4 label2 label5 label3 label6
but it doesn't happen always, and I don't seem to be able to control this behaviour. So how can I make it so that the labels width are fixed, and if needed they go to several lines?
2. The chart always starts with the tick, so the 1st and the last points are squeezed to the chart border. Is there a way to add a padding without ruining the chart grid? I tried decreasing min and increasing max limits on the x-axis, and it does create some padding between the points and the borders, but then the grid is not aligned with the points anymore. Is there a way to do this?
I can provide screenshots if needed.
Thanks in advance!
Hi.
What behavior would you like when you increase the extent? Bigger labels? Aligned in the middle? There is a property for affective their vertical alignement. The staggering behavior is initiated if the labels would have collided. They form as many rows as there is space allowed for to avoid intersecting.
There is currently no way to add margins around the displayed data without manually setting up the axis ranges. Which you can do with the numeric axes but not with the CategoryXaxis.
Hope this helps!
-Graham
I understand about the margins, thanks.
As for the labels: I know how to middle-align them to tick marks. The problem is that staggering doesn't happen always. Maybe the problem is that I'm using a DataTemplated TextBlock as a label (as per the blog entry on how to format DateTime labels) -- does the extent work in this case? Or should this be controlled by the TextBlock? Or both?
When you are using a datatemplated label the actual bounds of the label can be a factor. You may have to change the alignment properties on the root control of your template. To get a clearer picture of whats going on I'd recommend setting a border or a background color on your datatemplate so you can see the actual "bounds" of the label.
Also, if you have a project that we can use to reproduce what you are seeing, feel free to send it along.
Oops, looks like in all those experiments I got a bit lost and didn't correctly describe my problem.
We do not use the datatemplated labels anymore, and that's when the problem happens. When creating a small test app for you to check, I noticed that the unwanted behaviour happens when you have a category X axis, and the number of categories is quite bit, but the interval is not set, or is too small for the labels to be displayed completely. It looks like the chart tries to squeeze in all the labels, but only so much get displayed. If I increase the interval to a certain number (30 in my attached sample), -- voila! -- staggering is there. 20, 10 or less -- and there is no staggering, only as I said before some vertical space being eaten up (see comment starting with "NB" in the MainPage.xaml.cs and play with the values).
Please, find the attached project and let me know what you think.
Hi,
I haven't reviewed the logic recently, but its likely that it will only attempt the staggering if this would actually avoid collisions, o/w it presumably just resorts to clipping. So if you have many data points and set the interval to something low, then you might create a situation where even the staggering cannot prevent collisions.
This is the case. If the labels would collide even if staggering is applied, then staggering is not performed, instead clipping is applied.