I am needing to display a grid below a chart and the grid needs to be aligned with the physical chart itself (not the Y axis labels)
| -- Y1 Label --|-- Physical Chart is Displayed Here --|-- Y2 axis Label --|
|-- My Custom grid needs to display here --|
I can get the width of the physical chart via chart.Series[0].ActualWidth
But I cannot get the width of the 2 Y axis labels. These labels can also be configured by the user at runtim to display any number of decimal places, so their width may dynamically change.
So how can I get the Y1 and Y2 label widths easily? I am doing most of this in the code behind so programatic access is how I need to access thes widths.
ChartObj.Axes["y1Axis"].LabelSettings.Extent ALWAYS returns 50.
Thanks
Hi Rod,
You can get the VerticalAxisLabelPanel from the visual tree in the data chart and then use it's width. Code snippet can be seen below.
void GetDescendentsFromType(DependencyObject parent, Type type, ref List<DependencyObject> list) { for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++) { DependencyObject child = VisualTreeHelper.GetChild(parent, i); if (child.GetType() == type) list.Add(child); GetDescendentsFromType(child, type, ref list); } } // Usage: List<DependencyObject> verticalAxes = new List<DependencyObject>(); GetDescendentsFromType(xmDataChart1, typeof(VerticalAxisLabelPanel), ref verticalAxes);
Thanks Rob - works like a champ!
Any place in the documentation we could get a layout of the chartcontrol and all the pieces/parts Never knew there was a class like the VerticalAxisLabelPanel!
Rod