Jump to content
Software FX Community

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


DSimons
 Share

Recommended Posts

Hi,

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"

 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

 xmlns:cfx="http://schemas.softwarefx.com/chartfx/wpf/80"

 xmlns:cfxControls="clr-namespace:ChartFX.WPF.Controls;assembly=ChartFX.WPF"

 xmlns:cfxMotifs="http://schemas.softwarefx.com/chartfx/wpf/80/motifs"

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

  <UserControl.Resources>

  <XmlDataProvider x:Key="dummyData"

XPath="Data/DummyData">

  <x:XData>

  <Data xmlns="">

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

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

  </Data>

  </x:XData>

  </XmlDataProvider>

  </UserControl.Resources>

  <Grid>

  <cfx:Chart

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

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

cfxaddmotifs:Floating.Style}"

ItemsSource="{Binding

Source={StaticResource

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

cfx:Palettes.Basic}">

  <cfx:Chart.AllSeries>

  <cfx:AllSeriesAttributes>

  <!--<cfx:AllSeriesAttributes.Template>

 

<DataTemplate>

 

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

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

Path=CustomColor}"/>

 

</DataTemplate>

 

</cfx:AllSeriesAttributes.Template>-->

  </cfx:AllSeriesAttributes>

  </cfx:Chart.AllSeries>

 

  <cfx:Chart.AxisX>

  <cfx:Axis>

  <cfx:Axis.Labels>

  <cfx:AxisLabelAttributes

BindingPath="@LegendContent" />

  </cfx:Axis.Labels>

  </cfx:Axis>

  </cfx:Chart.AxisX>

  <cfx:Chart.Series>

  <cfx:SeriesAttributes

BindingPath="@Value" Content="Summary"

/>

  </cfx:Chart.Series>

  </cfx:Chart>

  </Grid>

</UserControl>

 

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

  <DataTemplate>

  <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}"/>

  <DataTemplate.Triggers>

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

  <DataTrigger.Value>

  <sys:Boolean>True</sys:Boolean>

  </DataTrigger.Value>

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

  </DataTrigger>

  </DataTemplate.Triggers>

  </DataTemplate> 

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; 

JuanC

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.

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

 Share

×
×
  • Create New...