tags:

views:

26

answers:

1

Does anyone know how to or found any good examples of explicitly setting the color of the data points series when using the WPFToolkit chart control? I would like to set this as a style in my XAML.

+1  A: 

You can set the Palette on the Chart. This example is for a ColumnSeries, but you can adapt it for whatever type you are using.

<charting:Chart ... Palette="{StaticResource MyPalette}">

The Palette definition looks like this:

<datavis:ResourceDictionaryCollection x:Key="MyPalette">
   <ResourceDictionary>
      <Style x:Key="DataPointStyle" BasedOn="{StaticResource ColumnSeries1Style}" TargetType="Control" />
   </ResourceDictionary>
   <ResourceDictionary>
      <Style x:Key="DataPointStyle" BasedOn="{StaticResource ColumnSeries2Style}" TargetType="Control" />
   </ResourceDictionary>
   ... add more if necessary
</datavis:ResourceDictionaryCollection>

The "ColumnSeries1Style" and "ColumnSeries1Style" styles define the background brush for the series:

<Style x:Key="ColumnSeries1Style" TargetType="Control">
   <Setter Property="Background" Value="{StaticResource Series1Brush}" />
</Style>

<Style x:Key="ColumnSeries2Style" TargetType="Control">
   <Setter Property="Background" Value="{StaticResource Series2Brush}" />
</Style>

You can define the brushes however you like. Here is how to get the gradient fill used in the default charts:

<Color x:Key="Series1Color" A="255" R="139" G="180" B="232" />
<Color x:Key="Series1HighlightColor" A="255" R="188" G="229" B="255" />
<RadialGradientBrush x:Key="Series1Brush">
   <RadialGradientBrush.RelativeTransform>
      <TransformGroup>
         <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819" />
         <TranslateTransform X="-0.425" Y="-0.486" />
      </TransformGroup>
   </RadialGradientBrush.RelativeTransform>
   <GradientStop Color="{StaticResource Series1HighlightColor}"/>
   <GradientStop Color="{StaticResource Series1Color}" Offset="1"/>
</RadialGradientBrush>
John Myczek
BasedOn="{StaticResource ColumnDataPointStyle}" is not resolving...am I looking at something wrong?
knockando
Sorry about that. ColumnDataPointStyle is a custom style I defined. You can just remove that "BasedOn". I updated the answer.
John Myczek