Chart issue - assign source and NullReferenceException

6 posts, 0 answers
  1. Heath
    Heath avatar
    11 posts
    Member since:
    Feb 2014

    Posted 26 Feb Link to this post

    "  at playing.Views.Dashboard.ConstructUtilisationBarGraph () [0x0014f] in /Users/marshallhp/Projects/playing/playing/Views/Dashboard.xaml.cs:50 \n  at playing.Views.Dashboard..ctor () [0x0002f] in /Users/marshallhp/Projects/playing/playing/Views/Dashboard.xaml.cs:25 \n  at playing.Views.MainPage.NavigateFromMenu (System.Int32 id) [0x000a0] in /Users/marshallhp/Projects/playing/playing/Views/MainPage.xaml.cs:42 \n  at playing.Views.MenuPage.<.ctor>b__3_1 (System.Object sender, Xamarin.Forms.SelectedItemChangedEventArgs e) [0x0004b] in /Users/marshallhp/Projects/playing/playing/Views/MenuPage.xaml.cs:47 \n  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 \n  at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.10.0.21/src/Xamarin.iOS/Foundation/NSAction.cs:178 \n--- End of stack trace from previous location where exception was thrown ---\n\n  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)\n  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.10.0.21/src/Xamarin.iOS/UIKit/UIApplication.cs:86 \n  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.10.0.21/src/Xamarin.iOS/UIKit/UIApplication.cs:65 \n  at playing.iOS.Application.Main (System.String[] args) [0x00001] in /Users/marshallhp/Projects/playing/playing.iOS/Main.cs:17 "

     

    Hi team, followed the example here (https://docs.telerik.com/devtools/xamarin/controls/chart/series/cartesian/line-series) and get this error in iOS simulator.

     

    Any help would be greatly appreciated. 

  2. Yana
    Admin
    Yana avatar
    4973 posts

    Posted 27 Feb Link to this post

    Hello Heath,

    I regret to hear you've come across an exception when using our RadChart control. 

    I would need more details on the exact scenario you have in order to reproduce and investigate the case.  I have checked the example from the referenced article, still, it's a basic setup and does not lead to the described exception.  In addition, the stack trace does not give me sufficient information what could have gone wrong.

    Would it be possible to try to isolate the issue in a separate runnable example? Or you can send us at least the files (xaml and code-behind) containing the Chart and the code for navigating to the corresponding view.  Please open a support ticket and attach them there.

    Thank you in advance.

    Regards,
    Yana
    Progress Telerik

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Heath
    Heath avatar
    11 posts
    Member since:
    Feb 2014

    Posted 27 Feb in reply to Yana Link to this post

    Thanks Yana

        public partial class Dashboard : ContentPage
        {
            ObservableCollection<Utilisation> DailyUtilisation;

            public Dashboard()
            {
                InitializeComponent();

                chrt_UtilisationWeekly.Series[0].SetBinding(ChartSeries.ItemsSourceProperty, "DailyUtilisation");

                //if (App.SessionUser == null || App.SessionUser.EmployeeCode == null || App.SessionUser.EmployeeCode == "")
                //    return;

                this.DailyUtilisation = ConstructUtilisationBarGraph();

            }

            ObservableCollection<Utilisation> ConstructUtilisationBarGraph()
            {
                var WeeklyLabour = App.Database.getUtilisation(App.SessionUser.EmployeeCode).Result;

                var results = new ObservableCollection<Utilisation>()
                                        {
                                            new Utilisation() { Day = "Monday", Hours = 0, ActivityCount = 0},
                                            new Utilisation() { Day = "Tuesday", Hours = 0, ActivityCount = 0},
                                            new Utilisation() { Day = "Wednesday", Hours = 0, ActivityCount = 0},
                                            new Utilisation() { Day = "Thursday", Hours = 0, ActivityCount = 0},
                                            new Utilisation() { Day = "Friday", Hours = 0, ActivityCount = 0},
                                            new Utilisation() { Day = "Saturday", Hours = 0, ActivityCount = 0},
                                            new Utilisation() { Day = "Sunday", Hours = 0, ActivityCount = 0}
                                        };

                //if (chrt_UtilisationWeekly.Palette != null)
                //    chrt_UtilisationWeekly.Palette.Entries.Clear();
                //else
                //    chrt_UtilisationWeekly.Palette = new Telerik.XamarinForms.Chart.ChartPalette();

                foreach (var day in DailyUtilisation)
                {

                    var daySum = WeeklyLabour
                                    .Where(x => x.DateDone.Date.ToString("dddd") == day.Day)
                                    .GroupBy(x => x.DateDone.Date)
                                    .Select(xl => new
                                    {
                                        Hours = xl.Sum(l => l.Hours),
                                        ActivityCount = xl.Count()
                                    }).ToList();

                    if (daySum.Count() > 0)
                    {
                        day.Hours = daySum.First().Hours;
                        day.ActivityCount = daySum.First().ActivityCount;
                    }

                    //chrt_UtilisationWeekly.Palette.Entries.Add(new Telerik.XamarinForms.Chart.PaletteEntry() { FillColor = day.BarColumnColour, StrokeColor = day.BarColumnColour });
                }

                return results;
            }
        }

        public partial class Utilisation
        {
            public string Day;
            public object DayFirstCharacter
            {
                get { return Day[0].ToString()+ Day[1].ToString(); }
            }
            public double Hours;
            public int ActivityCount;
            public Color BarColumnColour
            {
                get { return Day == DateTime.Now.Day.ToString("dddd") ? Xamarin.Forms.Color.FromRgb(0, 153, 204) : Xamarin.Forms.Color.FromRgb(129, 0, 204); }
            }
        }

     

    the xaml in a content page is this.

     

    <Grid VerticalOptions="Fill">
             <Grid.RowDefinitions>
                    <RowDefinition Height="40"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
            <telerikChart:RadCartesianChart x:Name="chrt_UtilisationWeekly" Grid.Row="1">
                <telerikChart:RadCartesianChart.HorizontalAxis>
                    <telerikChart:CategoricalAxis LabelFitMode="MultiLine"
                                          PlotMode="OnTicks" />
                </telerikChart:RadCartesianChart.HorizontalAxis>
                <telerikChart:RadCartesianChart.VerticalAxis>
                    <telerikChart:NumericalAxis />
                </telerikChart:RadCartesianChart.VerticalAxis>
                <telerikChart:RadCartesianChart.Series>
                    <telerikChart:LineSeries CategoryBinding="Day" 
                                            ValueBinding="Hours" 
                                            x:Name="chrtbr_Utilisation"/>
                    </telerikChart:RadCartesianChart.Series>
            </telerikChart:RadCartesianChart>
        </Grid>

    Assigning any itemssource causes it to crash, no itemssource just presents a single horizontal line as to be expected.

     

    Cheers

     

  4. Lance | Manager - Technical Support
    Admin
    Lance | Manager - Technical Support avatar
    1112 posts

    Posted 27 Feb Link to this post

    Hi Heath,

    The problem is Day and Hour are not properties in your model class, they are fields.  Try changing them to properties should fix the issue:

    public partial class Utilisation
    {
    	public string Day {get;set;}
    	
    	public object DayFirstCharacter
    	{
    		get { return Day[0].ToString()+ Day[1].ToString(); }
    	}
    	
    	public double Hours {get;set;}
    	
    	public int ActivityCount;
    	
    	public Color BarColumnColour
    	{
    		get { return Day == DateTime.Now.Day.ToString("dddd") ? Xamarin.Forms.Color.FromRgb(0, 153, 204) : Xamarin.Forms.Color.FromRgb(129, 0, 204); }
    	}
    }

    Let me know how it goes.

    Regards,
    Lance | Team Lead - US DevTools Support
    Progress Telerik

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. Heath
    Heath avatar
    11 posts
    Member since:
    Feb 2014

    Posted 27 Feb in reply to Lance | Manager - Technical Support Link to this post

    Thanks Lance,

     

    Just did the update and the same is still occuring :(

  6. Heath
    Heath avatar
    11 posts
    Member since:
    Feb 2014

    Posted 27 Feb in reply to Heath Link to this post

    Correction... It is working! Thanks kindly, really appreciate it.
Back to Top