Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
160
TimeSpan and Object values in XamPivotGrid
posted

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")
};


 

 

Parents
No Data
Reply
  • 7922
    Suggested Answer
    posted

    Hi,

     

    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 { getset; }
            public string Column { getset; }
            public long LongValue
            {
                get { return this.Value.Ticks; }
            }
     
            public TimeSpan Value { getset; }
        }

     

    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

Children