This is a migrated thread and some comments may be shown as answers.

Get ActualWidth of AxisY?

7 Answers 107 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Tony Ser
Top achievements
Rank 1
Tony Ser asked on 28 Aug 2010, 12:46 AM
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!

7 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 02 Sep 2010, 09:58 AM
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
0
Tony Ser
Top achievements
Rank 1
answered on 02 Sep 2010, 05:12 PM
Thank you for the reply and work around, I will give it a try when I have the chance!
0
Graham Ramsay
Top achievements
Rank 1
answered on 10 Nov 2010, 06:28 PM
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
0
Folvort
Top achievements
Rank 1
answered on 18 Nov 2010, 11:48 AM
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
0
Yavor
Telerik team
answered on 23 Nov 2010, 11:44 AM
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
0
Folvort
Top achievements
Rank 1
answered on 23 Nov 2010, 12:29 PM
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...
0
Yavor
Telerik team
answered on 25 Nov 2010, 07:23 AM
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
Tags
Chart
Asked by
Tony Ser
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Tony Ser
Top achievements
Rank 1
Graham Ramsay
Top achievements
Rank 1
Folvort
Top achievements
Rank 1
Share this question
or