Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1886
XamDataChart - Dimensions (width) of Y Axis labels and Physical Chart
posted

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

 

 

Parents
No Data
Reply
  • 34510
    Verified Answer
    Offline posted

    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);
     
Children