Hi,
I have two questions about XamPivotGrid:
1) How can I display TimeSpan values, defined in a custom FlatDataSource? I created a class PivotData with a value property of TimeSpan type. Then I fill a List<PivotData> with values, and create a FlatDataSource.This leaves the PivotGrid values empty (Something like "Drop Data Items here" shows up).2) Another thing that is somewhat related to this, is that I sometimes need int values, and sometimes need TimeSpan values. I tried to make the PivotData.Value property an "object", but the PivotGrid doesn't work with this either. I can imagine this could be done with a ValueConverter, but I don't really see how I can do this since the binding is on the FlatDataSource object. Also, this would still not work if the TimeSpan values do not display properly.PivotData and FlatDataSource:
public
class PivotData{ public string Row { get; set; } public string Column { get; set; } public TimeSpan Value { get; set; }}FlatDataSource = new FlatDataSource{ ItemsSource = pivotData, Cube = DataSourceBase.GenerateInitialCube("PivotData"), Rows = DataSourceBase.GenerateInitialItems("[Row]"), Columns = DataSourceBase.GenerateInitialItems("[Column]"), Measures = DataSourceBase.GenerateInitialItems("Value")};
As I can see from your post, you try to use “Value” property as measure. FlatDataSource is designed to work only with numeric values as measures. That is because the estimation can be made only on numbers. If you want to calculate timespan, you should wrap timespan property in long property.
public class PivotData { public string Row { get; set; } public string Column { get; set; } public long LongValue { get { return this.Value.Ticks; } } public TimeSpan Value { get; set; } }
Measures = DataSourceBase.GenerateInitialItems("LongValue")
You can use metadata to format the value
CubeMetadata cmd = new CubeMetadata { DataTypeFullName = typeof(PivotData).FullName };
cmd.DimensionSettings.Add(new DimensionMetadata { DisplayName = " LongValue ", SourcePropertyName = " LongValue ", DisplayFormat = "{0} %" }); fl.CubesSettings.Add(cmd);
Regards
Todor
Thank you, this does indeed show the values in the XamPivotGrid. I use an int value, as the .Seconds property is sufficient for my grid.
I do however still not know how to display the values like:
00:02:05
instead of just
125