Interactively changing axis font sizes

2 posts, 0 answers
  1. Joe
    Joe avatar
    11 posts
    Member since:
    May 2014

    Posted 30 Oct 2014 Link to this post

    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?
  2. Peshito
    Admin
    Peshito avatar
    497 posts

    Posted 03 Nov 2014 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top