Column Chart updated after data changed

Oct 2, 2013 at 10:55 AM
Edited Oct 2, 2013 at 10:58 AM
Hello,
I am developing a windows 8 phone app and using a column chart in one of the pages. The problem is the chart is not updated after data changed Unless i navigated backwards and forward.

the app architecture is MVVM, I put other elements in the page and updated the in the same method as a test and they updated successfully.

Also If i set the CategoryXAxis.Visibility to TRUE it generates NULL REFERENCE EXCEPTION

XAML


<chart:SparrowChart Foreground="{StaticResource PhoneAccentBrush}">
            <chart:SparrowChart.Legend>
                <chart:Legend Padding="10" Foreground="{StaticResource PhoneAccentBrush}" Header="Calories per every meal"/>
            </chart:SparrowChart.Legend>
            <chart:SparrowChart.XAxis>
                <chart:CategoryXAxis
                    Visibility="Collapsed"
                    Header="Categories"
                    />
            </chart:SparrowChart.XAxis>
            <chart:SparrowChart.YAxis>
                <chart:LinearYAxis
                CrossLineStyle="{StaticResource crossLineStyle}"  
                MinorLineStyle="{StaticResource minorcrossLineStyle}"
                MajorLineStyle="{StaticResource crossLineStyle}" 
                AxisLineStyle="{StaticResource axisLineStyle}" 
                MinValue="0" Interval="500"  
                MaxValue="5000"
                ShowCrossLines="True" Header="Calories" />
            </chart:SparrowChart.YAxis>
            <chart:ColumnSeries  
                                IsRefresh="True" 
                                Fill="{StaticResource PhoneAccentBrush}"
                                PointsSource="{Binding MealsChartData}"                           XPath="Meal" 
                                Foreground="{StaticResource PhoneAccentBrush}"
                                YPath="Calories">

            </chart:ColumnSeries>

</chart:SparrowChart>

ViewModel


private async void InitMealsData()
    {
        this.MealsChartData = new ObservableCollection<ChartModel>();
        Repository<Meal> meals = new Repository<Meal>();
        ObservableCollection<Meal> data= await meals.GetAll("Meals.xml");
        //Create collection from logged data in a certain day
        if (data.Count > 0) 
        {              
            foreach (Meal item in data)
            {
                if (item.Date.Date == this.SelectedDate.Value.Date)
                {
                    double MealTotalClas = 0;
                    foreach (Food f in item.Foods)
                    {
                        MealTotalClas += f.Calories;
                    }   

                    string MealName = item.MealType.ToString();
                    this.MealsChartData.Add(new ChartModel { Meal = MealName, Calories = MealTotalClas });                           
                }                   
            }
        }

    }       
This method called every time selected date changed;