This project is read-only.

Trying to draw column chart: System.InvalidOperationException: Sequence contains no elements

Dec 18, 2014 at 5:26 PM
I'm sometimes getting InvalidOperationException when trying to draw column chart.

XAML looks like this:
<charting:Chart Grid.Row="2"
                        Title="Column Chart"
                                ItemsSource="{Binding GraphData}"
                                IndependentValueBinding="{Binding Name}"
                                DependentValueBinding="{Binding Value}"
                                IsSelectionEnabled="True" />
CS looks like this:
private readonly ObservableDictionary defaultViewModel = new ObservableDictionary();

private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
  List<NameValueItem> items = new List<NameValueItem>();
  items.Add(new NameValueItem { Name = "Test1", Value = _random.Next(10, 100) });
  items.Add(new NameValueItem { Name = "Test2", Value = _random.Next(10, 100) });
  items.Add(new NameValueItem { Name = "Test3", Value = _random.Next(10, 100) });
  this.DefaultViewModel["GraphData"] = items;
As said, sometimes this works ok, but quite often an InvalidOperationException is thrown with the following trace:
System.InvalidOperationException: Sequence contains no elements
   at System.Linq.Enumerable.Min(IEnumerable`1 source)
   at WinRTXamlToolkit.Controls.DataVisualization.Charting.OrientedPanel.MeasureOverride(Size availableSize)
   at Windows.UI.Xaml.FrameworkElement.MeasureOverride(Size availableSize)
   at WinRTXamlToolkit.Controls.DataVisualization.Charting.DisplayAxis.MeasureOverride(Size availableSize)
   at Windows.UI.Xaml.UIElement.Measure(Size availableSize)
   at WinRTXamlToolkit.Controls.Data
Any ideas? Bar chart for example seems to be working ok, but column or line chart doesn't.

Thanks in advance.
Jan 28, 2015 at 9:43 PM
Edited Jan 28, 2015 at 9:44 PM
May be a bit too late but i died with this problem and came back to life when I figured it out that, not giving fixed width & height can sometimes cause this.
I just added Height=500 and this solved the problem. (Windows Phone 8.1 Runtime App)
Feb 23, 2016 at 10:27 PM
It is enough just to determine the size of chart. You can set fixed value of height/width or put chart in container e.g. Grid, DockPanel.