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

Dates & Grouping on X axis

4 Answers 82 Views
Chart
This is a migrated thread and some comments may be shown as answers.
scott
Top achievements
Rank 1
scott asked on 28 Nov 2012, 11:10 PM

I'm trying to get a simple count-on-Y and dates-on-X chart going.  I'm using the Telerik.Data SLDataTable and I have 29,515 rows of data in this particular table.  The table has columns "CaseID" and "CreationDate".  If I just throw the data at the chart without grouping I get the effect as seen in the picture.  If I add grouping then I get the exception below.

Can somebody tell me what I'm doing wrong?

The code:


m_Chart.myChart.SeriesMappings.Clear();

 

SeriesMapping seriesMapping = new SeriesMapping() { LegendLabel = "CaseId" };

seriesMapping.GroupingSettings.GroupDescriptors.Add(new ChartDayGroupDescriptor("CreationDate"));

m_Chart.myChart.DefaultView.ChartArea.AxisX.IsDateTime = true;

m_Chart.myChart.DefaultView.ChartArea.AxisX.LabelRotationAngle = 45;

m_Chart.myChart.DefaultView.ChartArea.AxisX.AutoRange = false;

m_Chart.myChart.DefaultView.ChartArea.AxisX.AddRange(

 Convert.ToDateTime(Xdc.MinValue).ToOADate(), Convert.ToDateTime(Xdc.MaxValue).ToOADate(), 1);

 

ItemMapping yMapping = new ItemMapping();

yMapping.DataPointMember = DataPointMember.YValue;

yMapping.FieldName = "CaseID";

yMapping.AggregateFunction = ChartAggregateFunction.Count;

 

ItemMapping xMapping = new ItemMapping();

xMapping.DataPointMember = DataPointMember.XValue;

xMapping.FieldName = "CreationDate";

 

seriesMapping.ItemMappings.Add(yMapping);

seriesMapping.ItemMappings.Add(xMapping);

m_Chart.myChart.SeriesMappings.Add(seriesMapping);

 

m_Chart.myChart.ItemsSource = table;


The exception:

System.ArgumentNullException was unhandled by user code
  Message=Value cannot be null.
Parameter name: body
  StackTrace:
       at System.Linq.Expressions.Expression.Lambda(Expression body, String name, Boolean tailCall, IEnumerable`1 parameters)
       at System.Linq.Expressions.Expression.Lambda(Expression body, ParameterExpression[] parameters)
       at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilder.CreateGroupKeySelectorExpression()
       at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilder.get_GroupKeySelectorExpression()
       at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilderBase.CreateQuery()
       at Telerik.Windows.Data.Expressions.GroupDescriptorCollectionExpressionBuilder.CreateChildQuery(GroupDescriptorExpressionBuilder childBuilder)
       at Telerik.Windows.Data.Expressions.GroupDescriptorCollectionExpressionBuilder.CreateQuery()
       at Telerik.Windows.Data.QueryableExtensions.GroupBy(IQueryable source, IEnumerable`1 groupDescriptors)
       at Telerik.Windows.Data.QueryableCollectionView.CreateView()
       at Telerik.Windows.Data.QueryableCollectionView.get_QueryableView()
       at Telerik.Windows.Data.QueryableCollectionView.CreateInternalList()
       at Telerik.Windows.Data.QueryableCollectionView.EnsureInternalList()
       at Telerik.Windows.Data.QueryableCollectionView.get_InternalList()
       at Telerik.Windows.Data.QueryableCollectionView.EnsureRootGroup()
       at Telerik.Windows.Data.QueryableCollectionView.get_RootQCVGGroup()
       at Telerik.Windows.Data.QueryableCollectionView.GroupedIndexOf(Object item)
       at Telerik.Windows.Data.QueryableCollectionView.InternalIndexOf(Object item)
       at Telerik.Windows.Data.QueryableCollectionView.TryRestorePreviousCurrency()
       at Telerik.Windows.Data.QueryableCollectionView.InitializeCurrencyOnRefresh()
       at Telerik.Windows.Data.QueryableCollectionView.RefreshOverride()
       at Telerik.Windows.Data.QueryableCollectionView.RefreshInternal()
       at Telerik.Windows.Data.QueryableCollectionView.RefreshOrDefer()
       at Telerik.Windows.Data.QueryableCollectionView.InvalidatePagingAndRefresh()
       at Telerik.Windows.Data.QueryableCollectionView.OnGroupDescriptorsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
       at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
       at Telerik.Windows.Data.RadObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
       at Telerik.Windows.Data.ObservableItemCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
       at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
       at Telerik.Windows.Data.RadObservableCollection`1.InsertItem(Int32 index, T item)
       at System.Collections.ObjectModel.Collection`1.Add(T item)
       at Telerik.Windows.Data.RadObservableCollection`1.AddRange(IEnumerable`1 items)
       at Telerik.Windows.Controls.Charting.DataBindingHelper.ProcessGrouping(SeriesMapping seriesMapping, QueryableCollectionView dataEngine, Int32 samplingThreshold, ZoomScrollSettings zoomScrollSettings, ISeriesDefinition defaultSeriesDefinition, AxisRangeState axisXRangeState)
       at Telerik.Windows.Controls.Charting.DataBindingHelper.ProcessMapping(SeriesMapping seriesMapping, QueryableCollectionView dataEngine, Int32 samplingThreshold, ZoomScrollSettings zoomScrollSettings, ISeriesDefinition defaultSeriesDefinition, AxisRangeState axisXRangeState)
       at Telerik.Windows.Controls.Charting.DataBindingHelper.ProcessMappings(SeriesMappingCollection seriesMappings, QueryableCollectionView dataEngine, Int32 samplingThreshold, ZoomScrollSettings zoomScrollSettings, ISeriesDefinition defaultSeriesDefinition, AxisRangeState axisXRangeState)
       at Telerik.Windows.Controls.Charting.DataBindingHelper.GenerateDataSeries(Object originalData, SeriesMappingCollection seriesMappings, ISeriesDefinition defaultSeriesDefinition, ChartFilterDescriptorCollection globalFilterDescriptors, ChartSortDescriptorCollection globalSortDescriptors, SamplingSettings samplingSettings, ZoomScrollSettings zoomScrollSettings, AxisRangeState axisXRangeState)
       at Telerik.Windows.Controls.RadChart.GenerateDataSeries(Object originalData, SeriesMappingCollection seriesMappings, ChartArea chartArea)
       at Telerik.Windows.Controls.RadChart.GenerateDataSeries(Object originalData)
       at Telerik.Windows.Controls.RadChart.Rebind(Object originalData)
       at Telerik.Windows.Controls.RadChart.ItemsSourcePropertyChanged(DependencyObject target, DependencyPropertyChangedEventArgs args)
       at Telerik.Windows.PropertyMetadata.PropertyChangeHook.OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
       at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
       at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isBindingInStyleSetter)
       at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
       at Telerik.Windows.Controls.RadChart.set_ItemsSource(Object value)
       at qv.ChartDesigner.DrawChart()
       at qv.ChartDesigner.OnDropInfo(Object target, DragDropEventArgs e)
       at Telerik.Windows.Controls.DragDrop.DragDropEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at Telerik.Windows.RadRoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at Telerik.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RadRoutedEventArgs routedEventArgs)
       at Telerik.Windows.RouteItem.InvokeHandler(RadRoutedEventArgs routedEventArgs)
       at Telerik.Windows.EventRoute.InvokeHandlersImpl(Object source, RadRoutedEventArgs args, Boolean raisedAgain)
       at Telerik.Windows.EventRoute.InvokeHandlers(Object source, RadRoutedEventArgs args)
       at Telerik.Windows.RadRoutedEventHelper.RaiseEvent(DependencyObject element, RadRoutedEventArgs args)
       at Telerik.Windows.DependencyObjectExtensions.RaiseEvent(DependencyObject element, RadRoutedEventArgs e)
       at Telerik.Windows.Controls.DragDrop.RadDragAndDropManager.DragDropProvider_DropInfo(Object sender, DragDropEventArgs e)
       at Telerik.Windows.Controls.DragDrop.DragDropProviderBase.RaiseDropInfo()
       at Telerik.Windows.Controls.DragDrop.DragDropProvider.FinishDrag()
       at Telerik.Windows.Controls.DragDrop.DragDropProvider.OnElementDrop(Object sender, DragEventArgs e)
       at Telerik.Windows.DragDrop.DragEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at Telerik.Windows.RadRoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at Telerik.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RadRoutedEventArgs routedEventArgs)
       at Telerik.Windows.RouteItem.InvokeHandler(RadRoutedEventArgs routedEventArgs)
       at Telerik.Windows.EventRoute.InvokeHandlersImpl(Object source, RadRoutedEventArgs args, Boolean raisedAgain)
       at Telerik.Windows.EventRoute.InvokeHandlers(Object source, RadRoutedEventArgs args)
       at Telerik.Windows.RadRoutedEventHelper.RaiseEvent(DependencyObject element, RadRoutedEventArgs args)
       at Telerik.Windows.DependencyObjectExtensions.RaiseEvent(DependencyObject element, RadRoutedEventArgs e)
       at Telerik.Windows.DragDrop.DragOperation.RaiseDragEvent(RoutedEvent dragEvent, DependencyObject target)
  InnerException:

4 Answers, 1 is accepted

Sort by
0
Petar Kirov
Telerik team
answered on 03 Dec 2012, 05:17 PM
Hi Scott,

I tested your code (with grouping) and I could not reproduce the exception you are receiving. 

A possible cause for the problem in the second scenario (without grouping) in which nothing is displayed is that you are setting manually the range of the X axis and probably there is no data in that range.

I am attaching a sample project which I made using your code. It would be helpful if you could modify it and send it back to us in a Support Ticket, so that we can reproduce the problem locally.

As a side note you can set the ShouldFlattenSeries GroupingSetting to true. Because you are using Count ChartAggregateFunction you will get one series per each unique CreationDate which would contain one series item - the number of data point with the same CreationDate. This setting will create one series containing all the counts.

Regards,
Petar Kirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
scott
Top achievements
Rank 1
answered on 03 Dec 2012, 06:26 PM
Hi Petar.

I was hoping the stack trace would match a footprint known to Telerik because before posting this question, I had already tried to come up with a simple reproducer and it also worked fine.  The real code is too large and too much work to shrink given my other priorities right now.

After posting the question I came up with this - that does what I want - and seems to do what the built-in date aggregation would do if I can get it working?

if (dateOnX)
                   {
                       Dictionary<DateTime, double> hDataPoints = new Dictionary<DateTime, double>();
 
                       // collapse dates to the users desired granularity
                       var v = from stuff in table.Rows
                               select
                                   new
                                   {
                                       YValue = stuff[dc.Name],
                                       XValue = XDateConverter((DateTime)stuff[Xdc.Name], dateGran)
                                   };
 
                       // apply the Y side aggregations selected by the user
                       var groups = v.GroupBy(stuff => stuff.XValue);
                       foreach (var date in groups)
                       {
                           switch (p.cbFunction.Text)
                           {
                               case "Count":
                                   hDataPoints[date.Key] = (from stuff in v where stuff.XValue == date.Key select stuff.YValue).Count();
                                   break;
                               case "Sum":
                                  ...
                                  ...
                           }
 
                       }
 
                       foreach (DateTime date in hDataPoints.Keys.OrderBy(key => key.Ticks))
                       {
                           series.Add(new DataPoint() { XValue = date.ToOADate(), YValue = (double)hDataPoints[date] });
                       }
 
                       m_Chart.myChart.DefaultView.ChartArea.DataSeries.Add(series);
 
                   }
 
       public DateTime XDateConverter(DateTime dateIn, string resType)
       {
           switch (resType)
           {
               case "Years":
                   return new DateTime(dateIn.Year, 1, 1);
               case "Months":
                   return new DateTime(dateIn.Year, dateIn.Month, 1);
               case "Days":
                   return new DateTime(dateIn.Year, dateIn.Month, dateIn.Day);
               case "Hours":
                   return new DateTime(dateIn.Year, dateIn.Month, dateIn.Day, dateIn.Hour, 0, 0);
               case "Minutes":
                   return new DateTime(dateIn.Year, dateIn.Month, dateIn.Day, dateIn.Hour, dateIn.Minute, 0);
               default:
                   break;
           }
           throw new Exception(string.Format("XDateConverter() bug dateIn={0} resType={1}",dateIn.ToString(),resType));
       }
0
Petar Kirov
Telerik team
answered on 06 Dec 2012, 03:22 PM
Hello Scott,

As soon as you are able to provide us with a project that reproduces your problem we will investigate the matter. You just need to open a formal support ticket with the project attached and list the steps to reproduce (if needed).

About your second question - I am not familiar with your project and I can not guarantee that this code will work. If it does solve your problem, you should have no trouble using it.
 
All the best,
Petar Kirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
scott
Top achievements
Rank 1
answered on 06 Dec 2012, 03:28 PM
Thanks Petar.  I'm not sure this code will work either ha ha - it seems to work fine.   My attempts at a simple reproducer failed to reproduce a problem so its a more subtle interaction in the larger code base.  My priority is "make it work" as opposed to "debug it" so we're all off the hook on this issue... 
Tags
Chart
Asked by
scott
Top achievements
Rank 1
Answers by
Petar Kirov
Telerik team
scott
Top achievements
Rank 1
Share this question
or