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

Interactively changing axis font sizes

1 Answer 135 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 30 Oct 2014, 08:18 PM
Is there any way to force a refresh/rebuild of the chart so that the labels are correctly positioned after a runtime change of the font size?  Ideally, in a MVVM way?

Currently, if you bind the font size to a property in the ViewModel and change it, the chart is not repositioned properly to accommodate the change in size.  See attached pics showing undesirable results of changing the font size, both when increasing or decreasing from the initial size.

Here's some code:

<chart:RadCartesianChart.VerticalAxis>
                <chartView:LinearAxis FontFamily="Segoe UI"
                        FontSize="{Binding AxisFontSize}"
                        Title="{Binding AxisTitle}"
                        Minimum="0"
                        Maximum="{Binding AxisMaxValue}"
                        LabelFormat="{Binding AxisLabelFormat}">
                </chartView:LinearAxis>
</chart:RadCartesianChart.VerticalAxis>

public double AxisFontSize
{
    get
    {
        return this._axisFontSize;
    }
    set
    {
        if ( this._axisFontSize != value )
        {
            this._axisFontSize = value;
            this.OnPropertyChanged( "AxisFontSize" );
            this.OnPropertyChanged( "AxisLabelFormat" );
        }
    }
}

What is the best way to accomplish a dynamic font size change?

1 Answer, 1 is accepted

Sort by
0
Peshito
Telerik team
answered on 03 Nov 2014, 09:24 AM
Hello,

Axis refreshing is not possible at that time. A workaround for the overlapping that we are aware of, is to set fixed width for your LabelTemplate. This will ensure that the labels will have enough space.
Copy Code
<DataTemplate x:Key="myLabelTemplate">
    <TextBlock Width="200" TextWrapping="Wrap" HorizontalAlignment="Right" Text="...." >
        .....
    </TextBlock>
</DataTemplate>

You should also reset the label template for instance when changing the font size in order for the workaround to apply:
this.verticalAxis.LabelTemplate = null;
this.verticalAxis.LabelTemplate = this.Resources["myLabelTemplate"] as DataTemplate;
Hope that helps.

Regards,
Peshito
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
ChartView
Asked by
Joe
Top achievements
Rank 1
Answers by
Peshito
Telerik team
Share this question
or