SfChart export image is black when not rendered

Hello 

So I have a SfTabControle with a few TabItems and on each tab there is a SfChart that I want to export to an image. So the fist Tab is shown when the program starts and the Image looks fine but then the second and 3rd chart only exports a black box to an image. When I click on tab 2 and 3 and the Charts gets rendered for the first time then the image looks fine. Is there a way to force the chart to be rendered even if it has not been viewed yet or is there some kind of other workaround for this. 


Attachment: 11_f58fd625.zip

6 Replies

GM Gayathri Manickam Syncfusion Team November 11, 2021 02:05 AM UTC

Hi Gerrit, 
 
Greetings from Syncfusion.    
    
This is a general update to let you know that our support team has taken out your query and we are validating the feasibility to achieve your requirement. We will update you the complete status on 11th November 2021.   
   
Regards,   
Gayathri M 



GM Gayathri Manickam Syncfusion Team November 12, 2021 02:36 AM UTC

Hi Gerrit,  
 
We analyzed your query “SfChart export image is black when not rendered” and we would like to let you know that chart will export as image properly when the chart is added on the visual tree otherwise it will export as black image.  
 
You can export the chart to image without rendering in UI by setting the chart to RootVisual in HwndSource and passing HwndSourceParameters to the HwndSource. Please refer below UG. 
 
 
Regards,  
Gayathri M 



GE Gerrit replied to Gayathri Manickam November 16, 2021 07:01 AM UTC

Hello 

I have added this to my code now but now it gives me the following errors 

{"The root Visual of a VisualTarget cannot have a parent."}


What could be causing this ?



GM Gayathri Manickam Syncfusion Team November 17, 2021 04:20 PM UTC

Hi Gerrit, 
 
We analyzed your query, as we don’t know the specific scenario, we cannot reproduce reported error at our end. We have prepared sample based on link below. 
 
 
Could you please revert us by modifying the provided sample based on your application along with replication procedure which will be helpful for us to provide you better solution at the earliest.   
  
Please find the tested sample below,   
 
 
Thanks,  
Gayathri M.  



GE Gerrit November 21, 2021 02:32 PM UTC

Hello 

I have managed to replicate my problem in your example by adding a tabControle and adding the SfChart in one of the TabItems. I have a feeling it has something to do with the chart now being a child of the Tabcontrole and can thus not be made a rootVisual. 


Attachment: Sample1298559604_(2)_d9e5d5c8.zip


GM Gayathri Manickam Syncfusion Team November 22, 2021 12:21 PM UTC

Hi Gerrit, 
 
We analyzed the provided sample, and we would like to let you know that "The root Visual of a VisualTarget cannot have a parent" exception occurs when the chart has already had a parent. If the chart is already added to the visual, we can directly save the chart as shown in the below code snippet, 
 
        private void Button_Click(object sender, RoutedEventArgs e) 
       
            var chart = A_chart; 
            if (A_chart.Parent == null
            {               
                HwndSourceParameters sourceParameters = new HwndSourceParameters(); 
                sourceParameters.HwndSourceHook = ApplicationMessageFilter; 
                HwndSource source = new HwndSource(sourceParameters); 
                source.RootVisual = chart;               
           
            chart.Save("Chart.png"); 
       
 
 
Thanks,  
Gayathri M. 


Loader.
Up arrow icon