This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I want to put custom label on the barchart, but when I try the following it is not working. The "Labels" in the BarSeries's LabelBinding is the property of the datacontext
|
|
|
Hello Gordon The LabelBinding property lets you specify a Binding used to extract a value from the data context of an individual data point. Based on the code you have posted, it looks like you won't need to set this property. To have custom labels on the data points, you'll first need to create a class to represent the data of a single data point. This class should have 2 double properties and 1 string property. (Or instead of 2 double properties, you may want a DateTime property or object property etc depending on what data you need to plot). Then you can populate the ItemsSource of the series with instances of your data class. Next, set the XBinding and YBinding properties to point to the appropriate properties on your data class. If you name the string property "Label", then the label style you have made will work fine now. You will not need to set the LabelBinding property. I have attached a small sample to make this more clear. Make sure to add a reference to your copy of the Mindscape.WpfElements.dll if you need to run it. -Jason |
|
|
Hi Jason, I have a few questions on this again: 1) If I did not DataLabelStyle, and directly use LabelBinding="{Binding Label}" or LabelBinding="{Binding X}",It still show the Y value of the point, why does not show Label or X field? 2) Change the DataLabelStyle in your example to the TextBox as: but I cannot edit the value, it would be nice if we can edit the value. Thanks Gordon |
|
|
Hello Gordon 1) Thanks for pointing this out. Looks like I can't change this without potentially breaking the current behavior. The reason this is not incorporated in the default label style yet is because LabelBinding was not added in a major version - it was added as a customer request. I've noted this done to be built into the default label style for the next version. For now, if you need to use the LabelBinding feature, you'll need a custom label style that binds to the LabelContent. 2) This is a cool idea. Here is an example label style that I used to get this effect:
The most likely thing you needed is the OverridesDefaultStyle setter. The default style sets IsHitTestVisible to false. The binding I've used on the TextBox is DataPoint.DataContext.Y. This binds directly to the property that determines the Y rendering position. Note that you do not want to use UpdateSourceTrigger=PropertyChanged because this will cause the chart to re-render as the value is being edited. Every time the chart is re-drawn, the TextBox will lose focus. Also, make sure your 'Y' property raises property changed notifications. A nice feature you might like to add is the ability to press the Enter key to finalize the value change. You'd probably do this by making a custom control that extends TextBox. Jason Fauchelle |
|
|
HI Jason, This is the old topic but I found some problem with graph refreshing: If the Datapointsthe DataSeries binding to is dynamic changing then the graph will not update. |
|
|
Hello I am not totally sure what you are referring to here. Just to clarify, are you talking about the idea of putting TextBox controls in the labels? If so, are you talking about the data points dynamically changing via TextBox input? or programmatic changes? Jason Fauchelle |
|
|
Hello The chart was not updating because the Chart control did not have support for IBindingList as an items source. This will be supported in the next nightly build which will resolve this issue. Jason Fauchelle |
|