Jump to content
Software FX Community

Binding SeriesAttribute's Fill Property using a column using a Pie Chart


Recommended Posts


I have a very simple pie chart that holds two pieces of data - On & Off. I would like to have the pallete of the on & off value be determined by the property "CustomColor" in the DataProvider below:


<UserControl x:Class="ActiveSummary"






 Height="250" Width="250" xmlns:cfxaddmotifs="http://schemas.softwarefx.com/chartfx/wpf/80/ext/motifs">


  <XmlDataProvider x:Key="dummyData"



  <Data xmlns="">

  <DummyData LegendContent="On"   Value="83"  CustomColor="Green" />

  <DummyData LegendContent="Off"   Value="17"  CustomColor="Red"  />







Gallery="Pie" x:Name="_ActiveChart"

Margin="2,2,2,2" Style="{x:Static




ResourceKey=dummyData}}" Palette="{x:Static








<Rectangle Width="{Binding Path=Width}"

Height="{Binding Path=Height}" Fill="{Binding













BindingPath="@LegendContent" />






BindingPath="@Value" Content="Summary"







I believe this can be done with a DataTemplate, as I have shown in the commented out code above, similar to the post here.


My question is: what is the proper DataTemplate to enable me to override the fill property of the Pie Chart so that I can determine the color that should be used for the series in XAML?

Link to comment
Share on other sites

This is a tough one, although you can in fact use a template to control the brush used in the pie slices as follows


  <Path Data="{Binding Path=Geometry}" Fill="{Binding Path=DataItem.@CustomColor}" Stroke="{Binding Path=Stroke}" StrokeThickness="{Binding Path=StrokeThickness}" StrokeDashArray="{Binding Path=StrokeDashArray}" Opacity="{Binding Path=Opacity}"/>


  <DataTrigger Binding="{Binding Path=Dimmed}">




  <Setter Property="Opacity" Value="0.25" />




The truth is that the brush of the series/point is used elsewhere, including a darker version of it as the stroke, in the legend box, dataview, etc. I think a better solution although it requires to write some code would be to loop through the data and use the Points property to change the fill brush, e.g.

chart1.Points[0].Fill = Brushes.Red;

chart1.Points[1].Fill = Brushes.Blue; 


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...