This is a migrated thread and some comments may be shown as answers.

PivotGrid with custom aggregates group TimeSpan and bounded ChartView

1 Answer 126 Views
PivotGrid and PivotFieldList
This is a migrated thread and some comments may be shown as answers.
Alexey
Top achievements
Rank 1
Alexey asked on 25 Apr 2016, 11:02 AM

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?

 

1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 27 Apr 2016, 02:03 PM
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.

Regards,
Hristo Merdjanov
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
PivotGrid and PivotFieldList
Asked by
Alexey
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or