PivotGrid with custom aggregates group TimeSpan and bounded ChartView

2 posts, 0 answers
  1. Alexey
    Alexey avatar
    1 posts
    Member since:
    Apr 2016

    Posted 25 Apr Link to this post

    Good day!

    I use PivotGrid in conjunction with ChartView.
    As one of the columns of data to implement a class for adding a field of type TimeSpan.

    This code implements summary of TimeSpan:

    /// <summary>
        /// Computes the sum of TimeSpan items during pivot grouping
        /// </summary>
        public class TimeSpanSum : AggregateFunction
            protected override AggregateValue CreateAggregate(Type dataType)
                return new TimeSpanAggregateValue();
            public override string DisplayName
                get { return PivotGridLocalizationProvider.CurrentProvider.GetLocalizedString(PivotStringId.Sum); }
            protected override void CloneCore(Cloneable source)
            protected override Cloneable CreateInstanceCore()
                return new TimeSpanSum();
            public override string ToString()
                return "Sum";

    This code adding aggregate description:

    dataProvider.AggregateDescriptions.Add(new PropertyAggregateDescription
        PropertyName = ObjectHelper<PivotGridUnitStateDto>.GetPropertyName(x => x.Duration),
        CustomName = "Duration",
        AggregateFunction = new TimeSpanSum(),
        StringFormatSelector = new TimeSpanStringFormatSelector()

    But ChartView generate exception on paint any data:

    Unable to bring the object type "System.TimeSpan" type "System.IConvertible". (Mscorlib)
    Program Location:
       в System.Convert.ToDouble(Object value)
       в Telerik.WinControls.UI.PivotGridChartDataProvider.UpdateChartCore()
       в Telerik.WinControls.UI.PivotGridChartDataProvider.UpdateChartData()
       в Telerik.WinControls.UI.PivotGridChartDataProvider.updateTimer_Tick(Object sender, EventArgs e)

    How can I fix this error?


  2. Hristo Merdjanov
    Hristo Merdjanov avatar
    664 posts

    Posted 27 Apr Link to this post

    Hello Alexey,

    Thank you for writing.

    The TimeSpan structure does not implement the IConvertible interface and hence the pivot engine cannot use the Convert.ToDouble method. This method call is needed in order to create PivotDataPoint objects which are later displayed by the attached RadChartView.

    If it would be possible for you please switch to a different data type, otherwise please explain your business scenario in more details so that we can get a better understanding of your task.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Hristo Merdjanov
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. DevCraft R3 2016 release webinar banner
Back to Top