There is a chart of chartingToolkit: Chart and there is a line with chartingToolkit: LineSeries points on it. Question: how is it possible, depending on the value of the object of the collection attached to the ItemSource, to color the dots in different colors (black and red)? Code and screenshot below.

<chartingToolkit:Chart x:Name="Chart1" Title="{x:Static helper:UIHelper.KartaX}" MinHeight="205" > <chartingToolkit:Chart.LegendStyle> <Style TargetType="visualizationToolkit:Legend"> <Setter Property="Width" Value="0" /> </Style> </chartingToolkit:Chart.LegendStyle> <chartingToolkit:Chart.TitleStyle> <Style TargetType="visualizationToolkit:Title"> <Setter Property="Margin" Value="0,0,0,-10" /> <Setter Property="HorizontalAlignment" Value="Center" /> </Style> </chartingToolkit:Chart.TitleStyle> <chartingToolkit:Chart.Axes > <chartingToolkit:LinearAxis Orientation="x" Minimum="{Binding MinRange}" Maximum="{Binding MaxRange}" Interval="1"/> <chartingToolkit:LinearAxis Orientation="Y" Minimum="{Binding MinXY}" Maximum="{Binding MaxXY}" /> </chartingToolkit:Chart.Axes> <chartingToolkit:LineSeries ItemsSource="{Binding ChartDetailList}" IndependentValuePath="SampleId" DependentValuePath="XMeasure" > <chartingToolkit:LineSeries.LegendItemStyle > <Style TargetType="{x:Type chartingToolkit:LegendItem}"> <Setter Property="Visibility" Value="Collapsed"/> </Style> </chartingToolkit:LineSeries.LegendItemStyle> <chartingToolkit:LineSeries.DataPointStyle> <Style TargetType="chartingToolkit:LineDataPoint"> <Setter Property="Foreground" Value="Red"/> <Setter Property="Background" Value="Black"/> <Setter Property="Opacity" Value="10" /> </Style> </chartingToolkit:LineSeries.DataPointStyle> </chartingToolkit:LineSeries> </chartingToolkit:Chart> 

enter image description here

  • If you want to paint only points, then you can write a trigger to change color depending on the value. I did not see the control itself, but WPF as a whole gives such an opportunity. - Monk
  • A trigger, then you can write, just what property changes, only the color of the dots? I did not find something like this and the color of the points is always the same as the color of the line. - Stiksol
  • snoopwpf.codeplex.com - this is what you can see from what the control is drawn. - Monk
  • Thanks for the link, a useful tool, but the question is still relevant - Stiksol

1 answer 1

In general, he resolved the issue by adding a trigger:

 <chartingToolkit:LineSeries.DataPointStyle> <Style TargetType="chartingToolkit:LineDataPoint"> <Setter Property="Opacity" Value="10" /> <Style.Triggers> <DataTrigger Binding="{Binding XAlarm, Converter={StaticResource ValueToBoolConverter}}" Value="True"> <Setter Property="Background" Value="Black"/> </DataTrigger> <DataTrigger Binding="{Binding XAlarm, Converter={StaticResource ValueToBoolConverter}}" Value="False"> <Setter Property="Background" Value="Red"/> </DataTrigger> </Style.Triggers> </Style> </chartingToolkit:LineSeries.DataPointStyle> 

Converter:

 public class ValueToBoolConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value != null) { if ((string)value == "0" ) { return true; } else { return false; } } return false; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } 

Now the points are repainted on the line, if true, then red, otherwise black.

Thanks, Monk, for the tool helped to solve the problem.

  • Then mark your answer as correct (this option will appear in a few days). - andreycha
  • Ok, thanks for the advice - Stiksol