有没有人知道在使用WPFToolkit图表控件时如何或找到明确设置数据点系列颜色的任何好例子?我想将它设置为我的XAML中的样式.
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}">
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)