<Grid.Resources>
<local:ColorConverter x:Key="colorConv"/>
</Grid.Resources>
<syncfusion:SfChart Header="Chart" Height="600" Width="800">
<syncfusion:SfChart.Resources>
<DataTemplate x:Key="labelTemplate">
<Border CornerRadius="2" BorderThickness="1" BorderBrush="Black" Padding="3" Margin="3" Background="{Binding Converter={StaticResource colorConv}, ConverterParameter=ValueY}" >
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Foreground="Black" Text="XValue :"/>
<TextBlock Foreground="Black" Text="{Binding ValueX}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Foreground="Black" Text="YValue :"/>
<TextBlock Foreground="Black" Text="{Binding ValueY}"/>
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
</syncfusion:SfChart.Resources>
...
<syncfusion:SfChart.Behaviors>
<syncfusion:ChartTrackBallBehavior/>
</syncfusion:SfChart.Behaviors>
<!--Initialize the series for SfChart-->
<syncfusion:ColumnSeries Label="Products" ItemsSource="{Binding Data}" Interior="Gray" XBindingPath="Name" YBindingPath="Height" ShowTooltip="False" TrackBallLabelTemplate="{StaticResource labelTemplate}" >
...
</syncfusion:ColumnSeries>
</syncfusion:SfChart> |
public class ColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
var chartPointInfo = value as ChartPointInfo;
double yvalue = System.Convert.ToDouble(chartPointInfo.ValueY);
if (yvalue < 50)
return new SolidColorBrush(Colors.Red);
else if (yvalue < 100)
return new SolidColorBrush(Colors.Yellow);
else if (yvalue < 150)
return new SolidColorBrush(Colors.Orange);
else
return new SolidColorBrush(Colors.Green);
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
} |