Style each item of a bar chart

2 posts, 0 answers
  1. dpl
    dpl avatar
    6 posts
    Member since:
    Feb 2012

    Posted 13 Aug 2013 Link to this post

    Hi all,

    looks like a simple problem, but I can't find a solution :-(  I have a bar chart with several items and a CustomGridLine, showing a limit value. Now I want to fill each item depending on his value. Green, if it is far away from the limit, yellow if near by and red if it is greater. Best solution will be a linear brush to fade the colors. Any hints?
  2. dpl
    dpl avatar
    6 posts
    Member since:
    Feb 2012

    Posted 15 Aug 2013 Link to this post

    I solved the problem :-)  The trick is to put the background in a property of the class for a single item. Then you can override the style and bind the background with the property.

    <Style x:Key="CustomBarStyle" TargetType="charting:Bar">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="charting:Bar">
                    <Canvas>
                        <Rectangle
                                x:Name="PART_DefiningGeometry"
                                Height="{TemplateBinding ItemActualHeight}"
                                Width="{TemplateBinding ItemActualWidth}"
                                Fill="{Binding DataItem.BackgroundBrush}" />
                        <Canvas.RenderTransform>
                            <ScaleTransform x:Name="PART_AnimationTransform" ScaleY="0" />
                        </Canvas.RenderTransform>
                    </Canvas>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top