Darin Daubert Posted August 25, 2009 Report Share Posted August 25, 2009 I currently have two series that are bound to a business object. The property names in the business object (let's say for this example TotalBonuses and AvgSalary) are not the labels I'd like shown in the LegendBox. Is there a way to override the labels to show something else? I'd prefer doing it in XAML, but if I have to in-code, that's also fine. Thank-you!Darin Quote Link to comment Share on other sites More sharing options...
Darin Daubert Posted August 25, 2009 Author Report Share Posted August 25, 2009 I think I found a way to do this -- I basically ended up creating my own DataTemplate. However, since both series would have to bind to a different label property on my business object, I'd have to create DataTemplates for each series. Is my approach the best way or is there another cleaner way? <cfx:Chart.Series> <cfx:SeriesAttributesCollection> <cfx:SeriesAttributes BindingPath="TotalBonuses"> <cfx:SeriesAttributes.ContentTemplate> <DataTemplate> <TextBlock Text="{Binding TotalBonusesLabel}" /> </DataTemplate> </cfx:SeriesAttributes.ContentTemplate> </cfx:SeriesAttributes> <cfx:SeriesAttributes BindingPath="AvgSalary"> <cfx:SeriesAttributes.ContentTemplate> <DataTemplate> <TextBlock Text="{Binding AvgSalaryLabel}" /> </DataTemplate> </cfx:SeriesAttributes.ContentTemplate> </cfx:SeriesAttributes> </cfx:SeriesAttributesCollection> </cfx:Chart.Series> Quote Link to comment Share on other sites More sharing options...
JuanC Posted August 25, 2009 Report Share Posted August 25, 2009 You do not have to use templates if all you want to show is a string, you can use the SeriesAttributes.Content property. Is the TotalBonusesLabel property exposed by the same object that exposes TotalBonuses? JuanC Quote Link to comment Share on other sites More sharing options...
Darin Daubert Posted August 25, 2009 Author Report Share Posted August 25, 2009 Ah -- that makes perfect sense. Here is what my object hierarchy looks like- ViewModel object (contains the TotalBonusesLabel property) - Employees - Employee (contains the TotalBonus property) The Chart's DataContext is the ViewModel, and the ItemSource is Employees. For my binding on the SeriesAttributes object, I'm using a relative source to get back to my ViewModel object for the label:Example: {Binding Path=DataContext.TotalBonusesLabel, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type cfx:Chart}}}Thank-you for the quick response!Darin Quote Link to comment Share on other sites More sharing options...
JuanC Posted August 25, 2009 Report Share Posted August 25, 2009 I just tried the following and it seemed to work without the RelativeSource in the binding <cfx:Chart Gallery="Bar" ItemsSource="{Binding Path=Employees}" x:Name="chart1"> <cfx:Chart.Series> <cfx:SeriesAttributes BindingPath="TotalBonuses" Content="{Binding Path=TotalBonusesLabel}"/> </cfx:Chart.Series> </cfx:Chart> JuanC Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.