We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Create SfChart asynchronously

Hi!

I really need your help, please:

I am trying to create a SfChart on a WPF window. Sometimes I have to load a lot of data in the chart which takes some seconds. In order not to block the UI I'd like to creat the Chart in an async Method and show it on the UI afterwards...

Is this anyhow possible? Because after creating a new SfChart Object in the async Mathod it tells me that the chart is an UI-Thread.

Is there anything I can do to improve the speed or not blocking the Tread?


Thank you very much!


Victor

5 Replies

DA Devi Aruna Maharasi Murugan Syncfusion Team January 26, 2017 12:58 PM UTC

Hi Victor, 
  
Thanks for contacting Syncfusion Support. 
  
We are unable to reproduce the reported problem at our end. We have prepared a demo sample based on your requirement and it can be downloaded from below link, 
  
Sample: Chart128475 
  
If you are still able to reproduce the reported problem, please revert us by modifying the provided sample. It would be helpful for us to serve you better. 
  
Regards, 
Devi 


  
  
  



VD Victor Dienstbier February 7, 2017 12:48 PM UTC

Hi Devi!

Thank you very much for your help!

I tried to solve the problem with your example, but it's not quite the answer...

I'm downloading data from a SQL Server with different measurements. For example I'd like to compare 10 different measurements. For each measurement I have an entry in the Observable Collection. No I'm adding one by one each measurment to a new SplineSeries.

That is what I'm doing:

private async void DiagrammQHErstellenAsync()

{

await Task.Run(() => DiagrammQH());

}


private void DiagrammQH()

{


//QH Diagramm




chrtKennlinie = diaQH;



chrtKennlinie.Header = "Förderhöhe";


//QH Diagramm




chrtKennlinieUebersichtCode = diaQHUebersicht;



chrtKennlinieUebersichtCode.Header = "Förderhöhe";


//X-Achsen


//Förderhöhe


chrtKennlinie.PrimaryAxis = new NumericalAxis()




{



Header = "Volumenstrom [l/s]",




Minimum = 0,



ShowTrackBallInfo = true




};



//Y-Achsen


//Förderhöhe


NumericalAxis Axis1 = new NumericalAxis()




{



Header = "Förderhöhe [m]",




Minimum = 0,



ShowTrackBallInfo = true




};


chrtKennlinie.SecondaryAxis = Axis1;


 



//Alle Serien aus Diagramm entfernen




chrtKennlinie.Series.Clear();



foreach (Pumpenmessdaten.MessungenSammlung Item in Vergleichsmessungen)




{



                   

                   

//SERIES


SplineSeries seriesQH = new SplineSeries()




{


IsSeriesVisible = Item.DatenMessung.IsChecked,


ItemsSource = Item.Messwerte,



XBindingPath = "QBerechnet",


YBindingPath = "HtotBerechnet",


ShowTooltip = true,


EnableAnimation = true,







AdornmentsInfo = new ChartAdornmentInfo()




{



Symbol = ChartSymbol.Ellipse,




SymbolWidth = 5,


SymbolHeight = 5


}


};


seriesQH.YAxis = Axis1;



//Adding Series to the Chart Series Collection




chrtKennlinie.Series.Add(seriesQH);







//Behavior


ChartCrossHairBehavior crossHairQH = new ChartCrossHairBehavior()




{



HorizontalAxisLabelAlignment = ChartAlignment.Center,


VerticalAxisLabelAlignment = ChartAlignment.Center




};



ChartZoomPanBehavior zoomPanBehaviorQH = new ChartZoomPanBehavior()




{



EnableZoomingToolBar = true,


HorizontalPosition = HorizontalAlignment.Right,


VerticalPosition = VerticalAlignment.Top,


ToolBarBackground = new SolidColorBrush(Colors.Transparent),


EnableMouseWheelZooming = true,


EnablePanning = true,


EnableSelectionZooming = true,


ZoomRelativeToCursor = true,


ResetOnDoubleTap = true,




MaximumZoomLevel = 10,



EnablePinchZooming = true




};


chrtKennlinie.Behaviors.Add(crossHairQH);


chrtKennlinie.Behaviors.Add(zoomPanBehaviorQH);


           


}


I hope you understand my problem now a little bit better :-)


Thank you very much for your help!





DA Devi Aruna Maharasi Murugan Syncfusion Team February 8, 2017 04:59 PM UTC

Hi Victor, 
  
Thanks for your update. 
  
We suggest you to set the datas alone using async method instead of creating chart in async method. We have prepared a demo sample based on your requirement and it can be downloaded from below link, 
  
Sample: AsyncSample 
  
Regards, 
Devi 






VD Victor Dienstbier February 15, 2017 09:02 AM UTC

Hi Devi!

Thanks again for your reply! I tried to approach the solution with your example, but it still takes a lot of time depending on the amount of Series I add to the diagramm.

In your example you create all needed data asyncrounously. I'm doing the same. I get the data from the SQL Server async and afterwards adding each measure to a new Series. Getting all data takes maybe a second for 1000 meaures. Adding them so the chart is what takes the time.

Is the an option where I don't need to do a foreach loop to add all the Series one by one?


Thank you very much! I also added a Screenshot with an example view of data. The creation took about a minute...

Attachment: ExampleView_5092960a.zip


DA Devi Aruna Maharasi Murugan Syncfusion Team February 16, 2017 01:18 PM UTC

Hi Victor, 
  
Thanks for your update. 
  
Query 1:  it still takes a lot of time depending on the amount of Series I add 
  
We suspect that, the delay due to rendering the normal chart series in UI. We can reduce the loading delay (rendering time) of chart series by using FastSeries instead of normal series. 
We have prepared a demo sample with 100 FastLineSeries for your reference and it can be downloaded from below link, 
  
Query 2: Is there an option where I don't need to do a foreach loop to add all the Series one by one? 
  
Since you need to create a separate instance for each series based on each measurement (as you mentioned in your previous update), we don’t have any other option than the foreach loop or for loop to add the series. 
  
Regards, 
Devi 





Loader.
Live Chat Icon For mobile
Up arrow icon