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