Jump to content
Software FX Community

Changing LegendBox series labels


Darin Daubert

Recommended Posts

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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.

×
×
  • Create New...