简体   繁体   English

如何为WPF饼图中的饼图切片设置默认颜色

[英]How to set a default color to the Pie slices in WPF Pie chart

I am using WPF Pie chart with Labels using the article from Zag studio .This chart refreshes for new values every 1 min. 我正在使用Zag studio中的文章将WPF饼图与标签一起使用。此图表每1分钟刷新一次新值。 It works fine, but why the color of the pie slices changes for every refresh? 效果很好,但是为什么每次刷新饼图的颜色都会改变? is there any possible way to set up default color.The pie chart which I am displaying has only two slices. 有没有办法设置默认颜色。我要显示的饼图只有两个部分。

What I have tried, 我尝试过的

 <customControls:LabeledPieChart>
  <customControls:LabeledPieChart.Palette>
   <dv:ResourceDictionaryCollection>
   <ResourceDictionary>                                               
     <Style TargetType="dvc:PieDataPoint">
     <Setter Property="Background" Value="Green"/>
     </Style>
    <Style TargetType="dvc:PieDataPoint">
   <Setter Property="Background" Value="Purple"/>
    </Style>
  </ResourceDictionary>
  </dv:ResourceDictionaryCollection>
 </customControls:LabeledPieChart.Palette>
 </customControls:LabeledPieChart> 

This above snippet returns exception as 上面的代码片段将异常返回为

'Set property 'System.Windows.ResourceDictionary.DeferrableContent' threw an exception. '设置属性'System.Windows.ResourceDictionary.DeferrableContent'引发了异常。

any body could help? 任何机构都可以帮忙吗? Thanks. 谢谢。

I have solved this issue myself with the help of this post 我已经解决了这个问题,自己对这个的帮助

here is the solution 这是解决方案

  <!--to set the Pie slice color-->
  <SolidColorBrush x:Key="color1" Color="Maroon" />
  <SolidColorBrush x:Key="color2" Color="DarkBlue" />

  <!--Pie Palette-->
  <customControls:LabeledPieChart.Palette>
    <dv:ResourceDictionaryCollection>
      <ResourceDictionary>
        <Style x:Key="DataPointStyle" TargetType="Control" >
          <Setter Property="Background" Value="{StaticResource color1}"/>
        </Style>
      </ResourceDictionary>
      <ResourceDictionary>
        <Style x:Key="DataPointStyle" TargetType="Control" >
          <Setter Property="Background" Value="{StaticResource color2}"/>
        </Style>
      </ResourceDictionary>
    </dv:ResourceDictionaryCollection>
  </customControls:LabeledPieChart.Palette>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM