locked
silverlight toolkit 3 chart show datapoints in different colors RRS feed

  • Question

  • Hello,

    I've got a problem in a scatterchart. I want to display datapoints in a limit as green datapoints, outside this limit they should be displayed in red.

     

    I don't know how to bind the ColorConverter in xaml

     

    Here's my code:

      <UserControl.Resources>      
            <local:ColorConverter x:Key="ColorConverter"
            DefaultColor="Green" LimitColor="Red" MinimumValue="550">
            </local:ColorConverter>
        </UserControl.Resources>

     <Style x:Key="CustomDataPointStylea" TargetType="chartingToolkit:ScatterDataPoint">
                    <!-- Pretty background brush -->
                    <Setter Property="Background">
                        <Setter.Value>
                            <SolidColorBrush Color="{Binding FormattedDependentValue, Converter={StaticResource ColorConverter}}">

                            </SolidColorBrush>
                        </Setter.Value>
                    </Setter>
                    <!-- Template with custom ToolTip -->
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="chartingToolkit:ScatterDataPoint">
                                <Grid>
                                    <Ellipse
                                        Fill="{TemplateBinding Background}"
                                        Stroke="{TemplateBinding BorderBrush}"
                                        StrokeThickness="{TemplateBinding BorderThickness}"/>
                                    <Ellipse>
                                        <Ellipse.Fill>
                                            <LinearGradientBrush>
                                                <GradientStop
                                                    Color="#77ffffff"
                                                    Offset="0"/>
                                                <GradientStop
                                                    Color="#00ffffff"
                                                    Offset="1"/>
                                            </LinearGradientBrush>
                                        </Ellipse.Fill>
                                    </Ellipse>

    .......

     

    //the cart in xaml

    .... <chartingToolkit:ScatterSeries                           
                                Name="ChartLine"
                                Title="West Store"
                                ItemsSource="{Binding}"
                                IndependentValuePath="Animal"
                                DependentValuePath="WestStoreQuantity"                           
                                DataPointStyle="{StaticResource CustomDataPointStylea}">  
                            </chartingToolkit:ScatterSeries>

     

     

    cs. code

     

     public class ColorConverter : IValueConverter
        {
            public int MinimumValue
            {
                get;
                set;
            }

            public Color LimitColor
            {
                get;
                set;
            }

            public Color DefaultColor
            {
                get;
                set;
            }

            private static ColorConverter instance = new ColorConverter();
            public static ColorConverter Instance
            {
                get
                {
                    return instance;
                }
            }

            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                int val = (int)value;
                if (val >= MinimumValue)
                    return LimitColor;
                else
                    return DefaultColor;
            }

            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                throw new Exception("The method or operation is not implemented.");
            }
        }

    Thanks

    Michael

     

     

    Saturday, August 14, 2010 8:48 AM

All replies

  • Hi,

    I found a solution.

    I added another property color a bound this dynamically.

    regards Michael

    Monday, August 16, 2010 12:44 PM