Hi all,
I am working on a project that receives data from USB and Plots using sfChart, after plot function I run export function in which I save Charts. However, the problem is whenever i save the charts it saves the previous state of the chart. this means after the first plotting the images are blank charts, and the second time it shows previous charts.
the exporting process is Ok for ex if I use a button, but i want this process to be automatic, any suggestions ?
Thanks in advance for your help.
|
private async void Button_Click(object sender, RoutedEventArgs e)
{
(this.DataContext as ViewModel).Data = new ObservableCollection<Model>()
{
new Model(11, 10),
new Model(12, 24),
new Model(13, 37),
new Model(14, 18),
new Model(15, 14),
new Model(16, 46),
new Model(17, 12),
};
await Task.Delay(10);
this.chart.Save("AfterExport.png");
} |
Hi Yuvaraj,
Thanks for your response. But the problem is the data i am plotting is big from 20 MB to 300 MB. So using delays might not be the best solution as it might not be correct for plots which take more time to be ready. Is there a more structured way? Like a property or event or smth like that?
|
<chart:SfChart x:Name="chart" LayoutUpdated="chart_LayoutUpdated" >
|
|
bool isUpdateData = false;
private async void Button_Click(object sender, RoutedEventArgs e)
{
Random random = new Random();
ObservableCollection<Model> data = new ObservableCollection<Model>();
for (int i = 0; i < 5000; i++)
{
data.Add(new Model(i, random.Next(100, 150)));
}
(this.DataContext as ViewModel).Data = data;
isUpdateData = true;
}
private void chart_LayoutUpdated(object sender, EventArgs e)
{
if (isUpdateData)
{
this.chart.Save("AfterExport.png");
isUpdateData = false;
}
} |
Hello again Yuvaraj,
I really appretiate your time and effort, it solved my problem.