Numeric Gauge - Initial value showing as NaN

4 posts, 1 answers
  1. Shanmugam
    Shanmugam avatar
    5 posts
    Member since:
    Oct 2010

    Posted 10 Dec 2010 Link to this post

    I have binded the data to the numeric gauge control, data which ever binded is showing perfectly, but at inital level it shows value as NaN in the NumericPositions.

    Please find the attached screenshot and here is my code

    <telerik:RadGauge x:Name="radGauge"
                              Height="45"
                              VerticalAlignment="Stretch"
                              HorizontalAlignment="Stretch"
                              Margin="-15,0,0,0"
                              BorderThickness="0">
                <telerik:NumericScale Min="0" Width="155" BorderThickness="0" >
                    <telerik:IndicatorList BorderThickness="0" >
                        <telerik:NumericIndicator x:Name="numericIndicator"
                                                  Format="{}{0:F2}"
                             Foreground="DarkBlue"
                                                  Left="0"
                                                  Top="0"
                                                  Value="{Binding ProjectVisibilityDataProp.Visibility}"
                                                  RelativeWidth="1.009"
                                                  RelativeHeight="0.99"
                                                  Background="White"
                                                  BorderThickness="0"
                                                  FontSize="45">
                            <telerik:NumberPosition CornerRadius="0" />
                            <telerik:NumberPosition CornerRadius="0" />
                            <telerik:NumberPosition CornerRadius="0"  RelativeWidth="0.5" />
                            <telerik:NumberPosition CornerRadius="0" />
                            <telerik:NumberPosition CornerRadius="0" />
                        </telerik:NumericIndicator>
                    </telerik:IndicatorList>
                </telerik:NumericScale>
            </telerik:RadGauge>

    Thanks
    Shanmugam
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 15 Dec 2010 Link to this post

    Hello Shanmugam,

    It is hard to say without your code, but I suppose that you didn't set an initial value to the correspondent property in your data context. I've created a sample application which uses a data model to bind numeric indicator value to. All things works just fine. The numeric indicator shows an initial value properly. Here it is XAML and code:

    <telerik:RadGauge x:Name="radGauge"
            Height="45"
            VerticalAlignment="Stretch" 
            HorizontalAlignment="Stretch"
            BorderThickness="0">
        <telerik:NumericScale Name="numericScale" Min="0" Width="155" BorderThickness="0" >
            <telerik:IndicatorList BorderThickness="0" >
                <telerik:NumericIndicator x:Name="numericIndicator" 
                    Format="{}{0:F2}"
                    Foreground="DarkBlue" 
                    Left="0" 
                    Top="0" 
                    Value="{Binding Value}"
                    RelativeWidth="1.009"
                    RelativeHeight="0.99"
                    Background="White" 
                    BorderThickness="0"
                    FontSize="45">
                    <telerik:NumberPosition CornerRadius="0" />
                    <telerik:NumberPosition CornerRadius="0" />
                    <telerik:NumberPosition CornerRadius="0"  RelativeWidth="0.5" />
                    <telerik:NumberPosition CornerRadius="0" />
                    <telerik:NumberPosition CornerRadius="0" />
                    </telerik:NumericIndicator>
            </telerik:IndicatorList>
        </telerik:NumericScale>
    </telerik:RadGauge>

    public class GaugeDataModel : INotifyPropertyChanged
    {
        private double valueToShow;
      
        public double Value
        {
            get
            {
                return this.valueToShow;
            }
      
            set
            {
                this.valueToShow = value;
                OnPropertyChanged("Value");
            }
        }
      
        public event PropertyChangedEventHandler PropertyChanged;
      
        private void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    public partial class MainPage : UserControl
    {
        private Random rnd = new Random();
      
        public MainPage()
        {
            InitializeComponent();
      
            GaugeDataModel model = new GaugeDataModel()
            {
                Value = this.GetNewValue(this.numericScale)
            };
            this.DataContext = model;
        }
      
        private double GetNewValue(RangedControl scale)
        {
            return scale.Min + (scale.Max - scale.Min) * rnd.NextDouble();
        }
    }


    Greetings,
    Andrey Murzov
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  3. DevCraft banner
  4. Shanmugam
    Shanmugam avatar
    5 posts
    Member since:
    Oct 2010

    Posted 15 Dec 2010 Link to this post

    Thank you very much for your reply.

    I am binding the value as you explained below, am facing problem when its getting loaded, before gets load of value it shows the value as NaN, Value="NaN" appears for a 1 or 2 sec's and after that binded value appears..

    Thanks
  5. Answer
    Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 17 Dec 2010 Link to this post

    Hello Shanmugam,

    I suppose that you populate your data from the kind of web or WCF service. So the ProjectVisibilityDataProp.Visibility property has not initial value. The default value for any unset doubles is NaN. If you want to show something other than NaN in the numeric indicator while actual values will be loaded you should set this initial value to the correspondent property like it is done in my code snippet, posted previously.

    Best wishes,
    Andrey Murzov
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
Back to Top