Get ActualWidth of AxisY?

8 posts, 0 answers
  1. Tony Ser
    Tony Ser avatar
    9 posts
    Member since:
    Jun 2010

    Posted 27 Aug 2010 Link to this post

    Hello,

    I am looking to move the legend from its default location, to be placed inside the charting 'plotting' area (to save space).  I have successfully moved to a custom chart layout so that I have control over where the legend is rendered, however, I am having troubles finding out exactly "where" to place it.  The chart plot area seems to move further right depending on if the Y Axis it has a title and by the size of the text on the marks.

    Is there a way to figure out the "ActualWidth" of the Y Axis (title, text and all)?

    Thanks!
  2. Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 02 Sep 2010 Link to this post

    Hello Tony Ser,

     Getting the ActualWidth of the axis is not supported currently. However you can apply a custom template on the ChartArea an set a fixed size on the Y axis like this:

    <Style TargetType="telerik:ChartArea">
        <Setter Property="Template2D">
            <Setter.Value>
                <ControlTemplate TargetType="telerik:ChartArea">
                    <Border Padding="{TemplateBinding Padding}"
                Margin="{TemplateBinding Margin}"
                Background="{TemplateBinding Background}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto" />
                                <RowDefinition Height="*" />
                                <RowDefinition Height="auto" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="auto" />
                            </Grid.ColumnDefinitions>
     
                            <telerik:AxisX2D x:Name="PART_AxisX" Style="{TemplateBinding AxisXStyle}" Grid.Row="2" Grid.Column="1" />
     
                            <telerik:AxisY2D x:Name="PART_AxisY" Style="{TemplateBinding AxisYStyle}" Grid.Row="1" Grid.Column="0" Width="50" />
     
                            <telerik:AdditionalAxes2DContainer x:Name="PART_AdditionalHorizontalAxesPanel" StackOrientation="Vertical" Grid.Row="0" Grid.Column="1"/>
     
                            <telerik:AdditionalAxes2DContainer x:Name="PART_AdditionalVerticalAxesPanel" StackOrientation="Horizontal"
                                                               Height="{TemplateBinding Height}" Grid.Row="1" Grid.Column="2" />
     
                            <telerik:ClipPanel x:Name="PART_PlotAreaPanel" Grid.Row="1" Grid.Column="1" Style="{TemplateBinding PlotAreaStyle}" >
                                <telerik:HorizontalStripLines2D x:Name="PART_HorizontalStripLines"  />
                                <telerik:VerticalStripLines2D x:Name="PART_VerticalStripLines"  />
                                <telerik:AnnotationLayer x:Name="PART_AnnotationLayer" ItemsSource="{TemplateBinding Annotations}" />
                                <telerik:VerticalMinorGridLines2D x:Name="PART_VerticalMinorGridLines" />
                                <telerik:HorizontalMinorGridLines2D x:Name="PART_HorizontalMinorGridLines" />
                                <telerik:HorizontalGridLines2D x:Name="PART_HorizontalGridLines"  />
                                <telerik:VerticalGridLines2D x:Name="PART_VerticalGridLines" />
                                <telerik:AdditionalPlotAreaAxes2DContainer x:Name="PART_AdditionalPlotAreaHorizontalAxesPanel" StackOrientation="Vertical" />
                                <telerik:AdditionalPlotAreaAxes2DContainer x:Name="PART_AdditionalPlotAreaVerticalAxesPanel" StackOrientation="Horizontal" />
                                 
                                <telerik:DragZoomLayerControl x:Name="PART_DragZoomLayer" Style="{TemplateBinding DragZoomLayerControlStyle}">
                                    <ItemsPresenter />
                                </telerik:DragZoomLayerControl>
     
                                <telerik:PlotAreaAxisY2D x:Name="PART_PlotAreaAxisY" Style="{TemplateBinding PlotAreaAxisYStyle}" />
                                <telerik:PlotAreaAxisX2D x:Name="PART_PlotAreaAxisX" Style="{TemplateBinding PlotAreaAxisXStyle}" />
                                <telerik:LabelsPanel x:Name="PART_LabelsPanel"/>
                            </telerik:ClipPanel>
     
                            <telerik:NoDataControl  x:Name="PART_NoData" Style="{TemplateBinding NoDataControlStyle}" Grid.RowSpan="3" Grid.ColumnSpan="3" />
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    Best wishes,
    Yavor Ivanov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Tony Ser
    Tony Ser avatar
    9 posts
    Member since:
    Jun 2010

    Posted 02 Sep 2010 Link to this post

    Thank you for the reply and work around, I will give it a try when I have the chance!
  4. Graham Ramsay
    Graham Ramsay avatar
    4 posts
    Member since:
    Oct 2006

    Posted 10 Nov 2010 Link to this post

    Rather than explicitly set the width of the PART_AxisY element as show in this example.  I've wired in a Size_Changed handler into the same element PART_AxisY, and when that fires I can get visiblity to what the axis width happens to be.     The style is specified in a UserControl Resource section of the UserControl I am developing, thus I get the sizechanged event visiblity in the proper code behind space.

    Graham Ramsay
  5. Folvort
    Folvort avatar
    7 posts
    Member since:
    Jun 2010

    Posted 18 Nov 2010 Link to this post

    Hi

    I'm used this code sample.
    But now Y axes are left aligned (sample.png)
    Can be axes right aligned ?

    Second question
    Y axis on chart 1 has no tick lines because all serie values are zero
    Can be some ticks displayed ? AutoRange for this axis is set to true,
    and i need to keep this value true
  6. Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 23 Nov 2010 Link to this post

    Hello Folvort,

    You can use the template from the first post and wrap the AxisY2D in a grid and right align it like this:

    <Grid Grid.Row="1" Grid.Column="0" Width="50">
        <telerik:AxisY2D x:Name="PART_AxisY" Style="{TemplateBinding AxisYStyle}" HorizontalAlignment="Right" />
    </Grid>

    In order to display some ticks the step has to be specified. When you are using auto range it is calculated based on the data. But when there is no data in the graph the step cannot be calculated by the auto range. You can display ticks by specifying the range manually. Please take a look on this topic in our help system that has the axes, range and ticks described.

    Sincerely,
    Yavor Ivanov
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  7. Folvort
    Folvort avatar
    7 posts
    Member since:
    Jun 2010

    Posted 23 Nov 2010 Link to this post

    Hi, Yavor Ivanov

    Thanks for reply. Problem with axis alignment are solved.

    But question with missing tick are not.
    I'm thinking you are not right. Graph is NOT EMPTY.
    Take the look to the sample.png from previous post
    Topmost graph HAS DATA. Yes, all values are zero, but
    they are NOT EMPTY. So this like as BUG,
    Autorange didnot work correctly ?

    Best regards.

    PS I want to set AutoRange = true, because sometimes
    values are not zeros. But manual range calculating
    for zeros and using autorange for other values are not serious...
  8. Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 25 Nov 2010 Link to this post

    Hello Folvort,

    Every axis has its own range. When you are using the Auto range functionality it uses the range formed by the data as a basis. When you have items that have only 0 as their Y value the data range for Y is 0. That's the reason why the RadChart Y axis ihas no ticks. If you want to show ticks and labels always on your axis consider using the biggest manual range that makes sense for your data.

    Another solution can be to listen to DataBound event and check if all the values are zeros and apply proper manual range.

    Please give the solutions above a try and pick the one that suits your case best. Hope this helps!

    All the best,
    Yavor Ivanov
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
Back to Top