sfChart Live Chart - Populating data at runtime

Hi,
I'm little bit lost getting this done. I want to make a chart showing temperature data. This is what I got so far.

XAML:
<charts:SfChart VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
                                                                <charts:SfChart.Title>
                                                                    <charts:ChartTitle Text="{x:Static localization:Strings.History}" TextColor="Blue"/>
                                                                </charts:SfChart.Title>

                                                                <charts:SfChart.Legend>
                                                                    <charts:ChartLegend OverflowMode="Wrap"/>
                                                                </charts:SfChart.Legend>

                                                                <charts:SfChart.PrimaryAxis>
                                                                    <charts:NumericalAxis AutoScrollingDelta="10" />
                                                                </charts:SfChart.PrimaryAxis>
                                                                <charts:SfChart.SecondaryAxis >
                                                                    <charts:NumericalAxis Minimum="0" Interval="50" Maximum="300"/>
                                                                </charts:SfChart.SecondaryAxis >
                                                                <charts:LineSeries ShowTrackballInfo="True"
                                                                    ItemsSource="{Binding HistoryBed}"  
                                                                    XBindingPath="Pos" YBindingPath="Temp" 
                                                                    ListenPropertyChange="True"/>
   
                                                            </charts:SfChart>


CS:
public class TemperatureHistory
    {
        public string Name { get; set; }
        public double Temp { get; set; }

        public int Pos { get; set; }
    }

private ObservableCollection<TemperatureHistory> _historyBed = new ObservableCollection<TemperatureHistory>();
        public ObservableCollection<TemperatureHistory> HistoryBed
        {
            get => _historyBed;
            set
            {
                if (_historyBed == value) return;
                _historyBed = value;
                OnPropertyChanged();
            }
        }

In the code behind I populate the data like this.
HistoryBed.Add(new TemperatureHistory() { Name = "Bed", Temp = Convert.ToDouble(Heatbed.Actual), Pos = Position++ });

However this seems not to work and lets the application crash. When I remove the code "HistoryBed.Add(...);" the application doesn't crash.
When I add some static data to the HistoryBed collection, it also works.
At the moment I'm testing on Android.

Running it on iOS is getting me an exception on startup of the form where the sfChart object is placed. Please
see the exception attached.
This happend after adding the sfChart nuget package to the project.

Thank you for your time and help,
Andreas



Attachment: exception_70a23cdc.zip

6 Replies 1 reply marked as answer

AR Andreas Reitberger June 20, 2020 10:07 AM UTC

I figured out what the exception caused.
It's the combination of any syncfsuion nuget package and the latest Xamarin-Version 4.7.0.968



HM Hemalatha Marikumar Syncfusion Team June 22, 2020 03:39 AM UTC

Hi Andreas Reitberger, 
 
Greetings from Syncfusion. 
 
We have checked the reported issue and tried to replicate the same at our end. But without knowing your entire use case, it seems like difficult to replicate and moreover stack trace related with Xamarin platform. So, for similar issue we have searched out and find the below one 
 
 
From their update, it seems like issue with Xamarin.Forms UPGRADED version. Could you please follow-up with that link to get further follow-ups.  
 
Regards,
Hemalatha M. 
 
 


Marked as answer

AR Andreas Reitberger June 26, 2020 06:19 AM UTC

Hi,
thanks for sharing the link. I temporaly downgraded to the last working version of Xamarin Forms.
Would you mind if you could share a code example for the original problem?

I want to make a "live chart" where I add temperature infos at runtime. However the chart is not updating if I remove or add values to the binded collection.
Thanks for your assist,
it's highly appreciated.

Andreas 


DD Devakumar Dhanapoosanam Syncfusion Team June 29, 2020 08:57 AM UTC

Hi Andreas Reitberger, 
 
Thanks for your update. 
 
We have prepared a sample to demonstrate the live update on chart and dynamic add or remove data points value to the collection as per your requirement and you can download the sample from the below link. 
 
 
Incase if your requirement is to update existing datapoint value dynamically please refer the below kb for more details, 
  
 
Please check the above and let us know if you need any further assistance on this. 
 
Regards, 
Devakumar D 



AR Andreas Reitberger June 29, 2020 04:10 PM UTC

Thank you for this example, this seems to work well for me!
Best,
Andreas


SJ Suyamburaja Jayakumar Syncfusion Team June 30, 2020 05:53 AM UTC

Hi Andreas Reitberger, 
 
We glad to know the given solution works, 
 
Please let us know if you need any further assistance. 
 
Regards, 
Suyamburaja J. 


Loader.
Up arrow icon