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

Style each item of a bar chart

1 Answer 72 Views
Chart
This is a migrated thread and some comments may be shown as answers.
dpl
Top achievements
Rank 1
dpl asked on 13 Aug 2013, 11:27 AM
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?

1 Answer, 1 is accepted

Sort by
0
dpl
Top achievements
Rank 1
answered on 15 Aug 2013, 07:59 AM
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>
Tags
Chart
Asked by
dpl
Top achievements
Rank 1
Answers by
dpl
Top achievements
Rank 1
Share this question
or