I have a general question on DataBinding that I'm hoping someone can answer, as I can't find good information on the binding syntax for a List of objects.
I have a List of ActivityData objects.
That object looks like the following:
public class ActivityData
{
public GeoPosition<GeoCoordinate> GeoPosition { get; set; }
public Timestamp {get; set; }
}
I bind to the list of objects. What I don't know is what the expression should be, e.g.
{Binding Timestamp} when the DataContext is set to the list results in a Binding expression error. Moreover, the GeoPosition property returns deeper properties that I'm interested in, such as Location and Speed. Does anyone know what the correct binding syntax would be for any of these cases?
So I found that this seems to have a positive effect:
<charts:XamDataChart x:Name="DataChart" >
<charts:XamDataChart.Axes>
<charts:CategoryXAxis x:Name="xmXAxis" ItemsSource="{Binding}" Label="{}{Timestamp}" >
<charts:CategoryXAxis.LabelSettings >
<charts:AxisLabelSettings Location="OutsideTop" Extent="35" />
</charts:CategoryXAxis.LabelSettings>
</charts:CategoryXAxis>
<charts:NumericYAxis x:Name="xmYAxis" >
<charts:NumericYAxis.LabelSettings >
<charts:AxisLabelSettings Location="OutsideLeft" Extent="55" />
</charts:NumericYAxis.LabelSettings>
</charts:NumericYAxis>
</charts:XamDataChart.Axes>
<charts:XamDataChart.Series>
<charts:SplineAreaSeries ValueMemberPath="GeoPosition.Location.Speed"
ItemsSource="{Binding}"
XAxis="{Binding ElementName=xmXAxis}"
YAxis="{Binding ElementName=xmYAxis}">
</charts:SplineAreaSeries>
</charts:XamDataChart.Series>
</charts:XamDataChart>
</Grid>
But no labels are showing up.... Not sure why.
So finally - that seems to work correctly. But the underlying data is in meters and I need to have the SplineAreaSeries to be able to use a Converter to show the data either using the English system or metric system (depending on what the user has selected). Is there any way to do this?
Hello,
Thank you for your post. I have been looking into it and it seems that I am missing something from your scenario. I could not understand if you want to change only the labels of the chart or you want to convert the entire data, depending on the users choice?
Looking forward to hearing from you.
Thanks for your reply. I have two charts working right now, but I have a number of issues I would like to solve:
1. Labelling the axes - not sure how to do this given your examples. I would like a label on the y axis for an Area Series to say Alttiude and one on the x axis to say time.
2. X-axis labels: It would be nice if these could be vertical (instead of horizontal). Right now I would like to get the time off the timestamp, not the whole thing. This is bound data, with the xaml looking like the following:
<charts:CategoryXAxis x:Name="speedXAxis" ItemsSource="{Binding Converter={StaticResource ChartSpeedConverter}}" Label="{}{Timestamp}" >
The Timestamp property has date and time. I've tried things like Timestamp.DateTime.ToShortTimeString() but that doesn't work (because it's a method call, not a property). Not sure if you can concatenate two properties together for the label.
3. Finally - the crosshair. I would like to enable this and have the data shown when the user moves across the chart, but I can't find any good examples on your web site that shows how to do this.
Any help would be appreciated.
So this kind of worked for the timestamp issue:
Label="{}{Timestamp.DateTime.Hour}:{Timestamp.DateTime.Minute}:{Timestamp.DateTime.Second}"
But it's a bloody mess and I'm not sure how to format it so everything has two digits (e.g., hours, mins, and seconds).