Indhi
Indhi

Reputation: 1694

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

any body could help? Thanks.

Upvotes: 2

Views: 5097

Answers (1)

Indhi
Indhi

Reputation: 1694

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>

Upvotes: 6

Related Questions