Hello, I am using a line series chart. However, whenever I entered the refresh button, the data points is still the same. How to make the chart refresh by clicking a button? As for the refresh button, I just call my chart function in the refresh button function.
//XAML
<chart:SfChart Margin="10">
<chart:SfChart.SecondaryAxis>
<chart:NumericalAxis Header="Value" FontSize="14" RangePadding="Additional"/>
</chart:SfChart.SecondaryAxis>
<chart:FastLineSeries Label="pH" ItemsSource="{Binding DataTable}"
XBindingPath="timestamp"
YBindingPath="ph" ShowTooltip="True">
<chart:FastLineSeries.AdornmentsInfo>
<chart:ChartAdornmentInfo ShowLabel="True" >
</chart:ChartAdornmentInfo>
</chart:FastLineSeries.AdornmentsInfo>
</chart:FastLineSeries>
<chart:FastLineSeries Label="EC" ItemsSource="{Binding DataTable}"
XBindingPath="timestamp"
YBindingPath="ec" ShowTooltip="True">
<chart:FastLineSeries.AdornmentsInfo>
<chart:ChartAdornmentInfo ShowLabel="True" >
</chart:ChartAdornmentInfo>
</chart:FastLineSeries.AdornmentsInfo>
</chart:FastLineSeries>
<chart:FastLineSeries Label="Temperature" ItemsSource="{Binding DataTable}"
XBindingPath="timestamp"
YBindingPath="temperature" ShowTooltip="True">
<chart:FastLineSeries.AdornmentsInfo>
<chart:ChartAdornmentInfo ShowLabel="True" >
</chart:ChartAdornmentInfo>
</chart:FastLineSeries.AdornmentsInfo>
</chart:FastLineSeries>
<chart:FastLineSeries Label="TDS" ItemsSource="{Binding DataTable}"
XBindingPath="timestamp"
YBindingPath="tds" ShowTooltip="True">
<chart:FastLineSeries.AdornmentsInfo>
<chart:ChartAdornmentInfo ShowLabel="True" >
</chart:ChartAdornmentInfo>
</chart:FastLineSeries.AdornmentsInfo>
</chart:FastLineSeries>
<chart:FastLineSeries Label="Salinity" ItemsSource="{Binding DataTable}"
XBindingPath="timestamp"
YBindingPath="salinity" ShowTooltip="True">
<chart:FastLineSeries.AdornmentsInfo>
<chart:ChartAdornmentInfo ShowLabel="True" >
</chart:ChartAdornmentInfo>
</chart:FastLineSeries.AdornmentsInfo>
</chart:FastLineSeries>
<chart:SfChart.Legend>
<chart:ChartLegend FontSize="15"/>
</chart:SfChart.Legend>
</chart:SfChart>
//Refresh Button function
//Chart function
//Datatable function
public object DataTable { get; set; }
Hi Ferlinatasha,
We have analyzed the provided code snippet and we would like to let you know that view model DataTable property does not notify the property changed while click refresh button to update chart. We can resolve this by implementing the INotifyPropertyChanged and raise property change while refresh chart data point as per in the below code example.
|
public class ViewModel : INotifyPropertyChanged { //Datatable function private object dataTable; public object DataTable { get { return dataTable; } set { dataTable = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DataTable))); } }
public event PropertyChangedEventHandler PropertyChanged; … |
https://www.syncfusion.com/kb/7731/how-to-update-an-existing-data-point-in-xamarin-forms-chart
Please check the above solution and let us know if you need any further assistance.
Regards,
Devakumar D
Hello Mr Devakumar D,
Thank you for the reply. To be honest, I am still a beginner in coding. So, if I implement this, do I still need the refresh button? And if yes, how I apply the refresh button?
Hi Ferlinatasha,
You can use a refresh button to update the DataTable with INotifyPropertyChanged. We would like to let you know that when binding the chart series ItemsSource property with the data model collection property implementing INotifyPropertyChanged, when data gets updated with a new instance property change raise and binding data update for the series.
Please find the example sample in the attachment and let us know if you need any further assistance.
Please refer below link for real time data update
https://www.syncfusion.com/kb/11416/how-to-create-a-real-time-chart-sfchart-using-mvvm-in-wpf
Regards,
Devakumar D