I have the WPFToolKit-Chart control which contains date and hours worked values. I want to change the color of column according to values. For example, I want to make the color orange when it exceeds working hours like the picture below.
I think it will be done using Trigger, but I could not complete the fiction.
This is my XAML markup:
xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
<chartingToolkit:Chart Name="chart1"
Title="Availability"
VerticalAlignment="Stretch">
<chartingToolkit:Chart.Series>
<chartingToolkit:ColumnSeries ItemsSource="{Binding MyGraph}"
IndependentValuePath="Key"
DependentValuePath="Value">
<chartingToolkit:ColumnSeries.DataPointStyle>
<Style TargetType="chartingToolkit:ColumnDataPoint">
<Setter Property="Background" Value="#00777F"/>
<Style.Triggers>
<Trigger Property=" Value > 8" Value="true"> <!--I need to adjust this part.-->
<Setter Property="Background" Value="Orange" />
</Trigger>
</Style.Triggers>
</Style>
</chartingToolkit:ColumnSeries.DataPointStyle>
</chartingToolkit:ColumnSeries>
</chartingToolkit:Chart.Series>
</chartingToolkit:Chart>
This is the view model:
private ObservableCollection<KeyValuePair<DateTime, int>> myGraph;
public ObservableCollection<KeyValuePair<DateTime, int>> MyGraph
{
get { return myGraph; }
set
{
myGraph = value;
OnPropertyChanged();
}
}
public ChartVM()
{
MyGraph = new ObservableCollection<KeyValuePair<DateTime, int>>()
{
new KeyValuePair<DateTime, int> (DateTime.Now, 8),
new KeyValuePair<DateTime, int> (DateTime.Now.AddDays(1), 8),
new KeyValuePair<DateTime, int> (DateTime.Now.AddDays(2), 11),
new KeyValuePair<DateTime, int> (DateTime.Now.AddDays(3), 7),
new KeyValuePair<DateTime, int> (DateTime.Now.AddDays(4), 12),
};
}