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

Creating linear gauge from code behind

1 Answer 64 Views
Gauge
This is a migrated thread and some comments may be shown as answers.
madladuk
Top achievements
Rank 2
madladuk asked on 05 Jul 2010, 05:14 PM
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> 

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 06 Jul 2010, 11:28 AM
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
Tags
Gauge
Asked by
madladuk
Top achievements
Rank 2
Answers by
Andrey
Telerik team
Share this question
or