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,
This is usually a good first stop when looking for the layout/pieces: http://help.infragistics.com/NetAdvantage/WPF/2012.2/CLR4.0/?page=Designers_Guide_Styling_Points_for_xamDataChart.html
It breaks down what the important parts of the chart are and gives you the object type to look for. From here I tested with using the Axis.Width/Axis.ActualWidth properties to see if this would work but it turns out the Axis type has a width and height that are the same as the chart itself. This wasn't useful to you so I turned to Snoop and that is how I found out about VerticalAxisLabelPanel. Snoop is a great tool for WPF developers and I recommend it to anyone. http://snoopwpf.codeplex.com/
As I said though, usually a good first place to look is at the styling points for the control in our documentation. After that if you haven't found what you're looking for, snoop it.
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
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);