How to apply gradient fill for stacked bar correctly

2 posts, 0 answers
  1. Sam
    Sam avatar
    18 posts
    Member since:
    Nov 2012

    Posted 05 Dec 2012 Link to this post

    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);
            }

  2. Sam
    Sam avatar
    18 posts
    Member since:
    Nov 2012

    Posted 05 Dec 2012 Link to this post

    Never mind. I need to sum the values (smack self on the head).  
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top