Update Charts on Separate Pages

I have an app with several pages that display various data in real time. However, every time I navigate to a different page, the chart is cleared and starts over. How can I keep the charts updating constantly while still being able to navigate between pages?

3 Replies

MK Muneesh Kumar G Syncfusion Team August 22, 2018 12:57 PM UTC

Hi Ben,  
  
Greetings from Syncfusion, we have analyzed your query and we would like to inform you that while navigate page in UWP, each time new instance created for page view. Thereby, chart also get reinitialized for rendering. So, we suggest you to use Pivot view to resolve this problem. Please find the code snippet below.  
 
Code snippet [XAML]: 
         <Pivot> 
            <PivotItem Header="Chart 1"> 
                <chart:SfChart x:Name="Chart" Margin="0,20,20,0" AreaBorderThickness="0,1,1,1" > 
 
                    .. 
                </chart:SfChart> 
            </PivotItem> 
            <PivotItem Header="Chart 2"> 
                <chart:SfChart x:Name="Chart1" Margin="0,20,20,0" AreaBorderThickness="0,1,1,1"> 
 
                    .. 
                </chart:SfChart> 
            </PivotItem> 
        </Pivot> 
  
We have prepared a sample based on this, please find the sample from the following location.  
 
Sample:  
 
Please refer below user documentation for more details about Pivot.  
 
 
Please let us know if you have any other queries.  
  
Thanks,  
Muneesh Kumar G 



BE Ben August 22, 2018 05:11 PM UTC

Thank you for the reply, but I've solved the issue in a different manner. By declaring the item source for a given chart in the app's shell page to be static, it doesn't get cleared upon navigation to other pages.

In shellpage.xaml.cs:
public static ObservableCollection<DataSet> ChartData = new ObservableCollection<DataSet>();

In chartpage.xaml.cs:

        public ChartPage()
        {
            InitializeComponent();
            foreach (Syncfusion.UI.Xaml.Charts.SplineSeries _ls in Chart.Series)
            {
                _ls.ItemsSource = ShellPage.ChartData;
            }
        }


MK Muneesh Kumar G Syncfusion Team August 23, 2018 04:33 AM UTC

Hi Ben,

Glad that the problem has been resolved and please get back to us if you need any other assistance. 

Regards,
Muneesh Kumar G.

Loader.
Up arrow icon