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

How to apply gradient fill for stacked bar correctly

1 Answer 127 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 05 Dec 2012, 06:27 PM
Note in the attached file that the gradient is applied to each individual value that makes up the bar fragment.
I want to set the gradient fill so it is applied only once to the fragment of the bar where it belongs.  How do I do that?
Thanks
<Window.Resources>
          
        <DataTemplate x:Key="AETemplate">
            <Rectangle>
                <Rectangle.Fill>
                    <RadialGradientBrush>
                        <GradientStop Color="#FF6DA7B6"/>
                        <GradientStop Color="#FF077085" Offset="1"/>
                    </RadialGradientBrush>
                </Rectangle.Fill>
            </Rectangle>
        </DataTemplate>
  
  
        <DataTemplate x:Key="STPTemplate">
            <Rectangle>
                <Rectangle.Fill>
                    <RadialGradientBrush>
                        <GradientStop Color="#FFE0DFDA"/>
                        <GradientStop Color="#FFC2BE57" Offset="1"/>
                    </RadialGradientBrush>
                </Rectangle.Fill>
            </Rectangle>
        </DataTemplate>
  
  
        <Style TargetType="{x:Type telerik:BarSeries}" x:Key="AEStyle">
            <Setter Property="Background">
                <Setter.Value>
                    <RadialGradientBrush>
                        <GradientStop Color="#FF6DA7B6"/>
                        <GradientStop Color="#FF077085" Offset="1"/>
                    </RadialGradientBrush>
                </Setter.Value>
            </Setter>
        </Style>
  
  
        <Style TargetType="Border" x:Key="STPStyle">
            <Setter Property="Background">
                <Setter.Value>
                    <RadialGradientBrush>
                        <GradientStop Color="#FFE0DFDA"/>
                        <GradientStop Color="#FFC2BE57" Offset="1"/>
                    </RadialGradientBrush>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
          
        <chart:RadCartesianChart x:Name="theChart">
            <chart:RadCartesianChart.HorizontalAxis>
                <chartView:CategoricalAxis FontFamily="Segoe UI" FontSize="12"  />
            </chart:RadCartesianChart.HorizontalAxis>
            <chart:RadCartesianChart.VerticalAxis>
                <chartView:LinearAxis FontFamily="Segoe UI" FontSize="12"
                                    Title="The Chart" 
                                    Minimum="0" Maximum="150"   />
            </chart:RadCartesianChart.VerticalAxis>
            <chart:RadCartesianChart.Grid>
                <chartView:CartesianChartGrid MajorLinesVisibility="XY" />
            </chart:RadCartesianChart.Grid>
        </chart:RadCartesianChart>
          
        <StackPanel Orientation="Horizontal" Grid.Row="1">
            <TextBox x:Name="tb" Height="30" Width="100"></TextBox>
            <Button Content="Click" Click="Button_Click" Height="30" Width="150" ></Button>
        </StackPanel>
    </Grid>
</Window>

private void AddSeries(string tag)
        {
            if(GroupedDataGroups == null)
                GroupedDataGroups = GroupedData.Groups.Cast<GroupingImpl<string, LoadStatistic>>();
  
            Style style;
            DataTemplate template;
  
            if (theChart.Series.Count == 0)
            {
                style = FindResource("AEStyle") as Style;
                template = FindResource("AETemplate") as DataTemplate;
            }
            else if (theChart.Series.Count == 1)
            {
                style = FindResource("STPStyle") as Style;
                template = FindResource("STPTemplate") as DataTemplate;
            }
            else
            {
                style = null;
                template = null;
            }
              
            var itemsSource = GroupedDataGroups.Where(x => x.Key.ToString() == tag).First().Items;
  
            var series = new Telerik.Windows.Controls.ChartView.BarSeries 
            
                Tag = tag,
                CombineMode = ChartSeriesCombineMode.Stack,
                CategoryBinding = new PropertyNameDataPointBinding("PeriodEnding"),
                ValueBinding = new PropertyNameDataPointBinding("TradeCount"),
                ItemsSource =  itemsSource,
                  
                //,  DefaultVisualStyle = style
            };
            series.PointTemplates.Add(template);
            theChart.Series.Add(series);
        }

1 Answer, 1 is accepted

Sort by
0
Sam
Top achievements
Rank 1
answered on 05 Dec 2012, 09:27 PM
Never mind. I need to sum the values (smack self on the head).  
Tags
Chart
Asked by
Sam
Top achievements
Rank 1
Answers by
Sam
Top achievements
Rank 1
Share this question
or