更改 WPFToolkit 图表控件的默认颜色

发布于 2024-09-18 13:44:48 字数 73 浏览 2 评论 0原文

有谁知道如何在使用 WPFToolkit 图表控件时显式设置数据点系列的颜色或找到任何好的示例?我想将其设置为 XAML 中的样式。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

好听的两个字的网名 2024-09-25 13:44:48

您可以在图表上设置调色板。此示例适用于 ColumnSeries,但您可以根据您使用的任何类型进行调整。

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

调色板定义如下所示:

<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>

“ColumnSeries1Style”和“ColumnSeries1Style”样式定义系列的背景画笔:

<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>

您可以根据需要定义画笔。以下是如何获取默认图表中使用的渐变填充:

<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>

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>
梦屿孤独相伴 2024-09-25 13:44:48

以防万一有人感兴趣,有一种更简单的方法。您只需在 ColumnSeries 中设置 DataPointStyle 并更改 Background 属性即可。

<DVC:ColumnSeries IndependentValueBinding="{Binding Path=Key}" 
            DependentValueBinding="{Binding Path=Value}">
                <DVC:ColumnSeries.DataPointStyle>
                    <Style TargetType="DVC:ColumnDataPoint">
                        <Setter Property="Background" Value="#00777F"/>
                    </Style>
                </DVC:ColumnSeries.DataPointStyle>

            </DVC:ColumnSeries>

Just in case anybody is interested, there is a simpler way of doing it. You just need to set the DataPointStyle in the ColumnSeries and change the Background property.

<DVC:ColumnSeries IndependentValueBinding="{Binding Path=Key}" 
            DependentValueBinding="{Binding Path=Value}">
                <DVC:ColumnSeries.DataPointStyle>
                    <Style TargetType="DVC:ColumnDataPoint">
                        <Setter Property="Background" Value="#00777F"/>
                    </Style>
                </DVC:ColumnSeries.DataPointStyle>

            </DVC:ColumnSeries>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文