Creating linear gauge from code behind

2 posts, 0 answers
  1. madladuk
    madladuk avatar
    126 posts
    Member since:
    Dec 2009

    Posted 05 Jul 2010 Link to this post

    Hi, followed the tutorials and I'm trying to create a linear gauge from code behind, however nothing shows; code snippet below

     void loadItem()  
            {  
                LinearScale scale = new LinearScale();  
                scale.Min = Convert.ToDouble(dashitem.minvalue);  
                scale.Max = Convert.ToDouble(dashitem.maxvalue);  
                scale.Width = 70;  
     
                // add a linear bar, already bound to the stock  
                scale.Indicators.Add(getLinearBar(dt.Rows[0]));  
     
                // initialize a stack panel to contain a text label  
                // and scale. Add the stack panel to the stack panel  
                // already in the xaml markup  
                StackPanel stackPanel = new StackPanel();  
                stackPanel.VerticalAlignment = VerticalAlignment.Stretch;  
                stackPanel.Children.Add(scale);  
                spScales.Children.Add(stackPanel);  
            }  
     
            private LinearBar getLinearBar(DataRow row)  
            {  
                LinearBar linearBar = new LinearBar();  
                linearBar.Value = Convert.ToDouble(row[dashitem.yfield]);  
                linearBar.StartWidth = .1;  
                linearBar.EndWidth = .1;  
                linearBar.RelativeHeight = 0.9;  
                 
                return linearBar; 
     <Grid x:Name="LayoutRoot">  
            <control:RadGauge x:Name="radGauge1">  
                <StackPanel x:Name="spScales" Orientation="Horizontal" HorizontalAlignment="Center" Margin="10" > 
                      
                </StackPanel> 
            </control:RadGauge> 
        </Grid> 
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 06 Jul 2010 Link to this post

    Hi Paul,

    The linear scale elements have white color by default. So, it looks like that the scales are not shown.
    You can change the background of the stack panel or to add each linear scale using LinearGauge container or to change colors of the scale elements like this:
    void loadItem()
    {
        LinearScale scale = new LinearScale();
        scale.Min = Convert.ToDouble(dashitem.minvalue);
        scale.Max = Convert.ToDouble(dashitem.maxvalue);

        
    scale.BorderBrush = new SolidColorBrush(Colors.Black);
        scale.MajorTick.Background = new SolidColorBrush(Colors.Black);
        scale.MiddleTick.Background = new SolidColorBrush(Colors.Black);
        scale.MinorTick.Background = new SolidColorBrush(Colors.Black);
        scale.Label.Foreground = new SolidColorBrush(Colors.Black);

        
    scale.Width = 70;

        
    // add a linear bar, already bound to the stock   
        scale.Indicators.Add(getLinearBar(dt.Rows[0]));

        
    // initialize a stack panel to contain a text label   
        // and scale. Add the stack panel to the stack panel   
        // already in the xaml markup   
        StackPanel stackPanel = new StackPanel();
        stackPanel.VerticalAlignment = VerticalAlignment.Stretch;
        stackPanel.Children.Add(scale);
        spScales.Children.Add(stackPanel);
    }
    private LinearBar getLinearBar(DataRow row)
    {
        LinearBar linearBar = new LinearBar();
        linearBar.Value = Convert.ToDouble(row[dashitem.yfield]);
        linearBar.StartWidth = .1;
        linearBar.EndWidth = .1;
        linearBar.RelativeHeight = 0.9;

        
    linearBar.Background = new SolidColorBrush(Colors.Gray);

        
    return linearBar;
    }

    Best wishes,
    Andrey Murzov
    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. DevCraft banner
Back to Top