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

How to change SfChart background when calling the Save method

Hi,

is it possible to change the background color it is used to cretate the image file when the SfChart.Save method is called?
I have, in fact, situations where the users changes the background color of the App using SfSkinManager and it seems to me that the Save method always uses the current GUI background color to produce the image file.
But in this case, it should be better for me to force a fixed background color (say Transparent or White), when saving instead of using the current background GUI color set by the user.
Is it possible to do this ?

Silvio Scattaglia

3 Replies

DS Durgadevi Selvaraj Syncfusion Team August 31, 2017 12:37 PM UTC

Hi Silvio, 
 
Thanks for contacting Syncfusion Support. 
 
We have analyzed your requirement and can be achieved by applying visual styles as Office2016White before save the chart and then we can set existing Visual Style to the chart as like in the below code, 
MainWindow.xaml: 
<Button Content="Save" Width="100" Height="50" Click="Button_Click"/> 
 
MainWindow.cs 
 
  private async void Button_Click(object sender, RoutedEventArgs e) 
  { 
 
            Syncfusion.SfSkinManager.SfSkinManager.SetVisualStyle(chart, Syncfusion.SfSkinManager.VisualStyles.Office2016White); 
            await Task.Delay(50); 
 
            chart.Save("a.png"); 
 
            Syncfusion.SfSkinManager.SfSkinManager.SetVisualStyle(chart, Syncfusion.SfSkinManager.VisualStyles.Blend); 
 
 
   } 
 
Please find the output screenshots, 
 
1.Before saving the  chart. 
 
2.Saved image of the chart. 
 
 
Also, we can achieve your requirement (saving chart with white background) by changing the chart Background and AreaBackground as white before save the chart and then we can set chart Background and AreaBackground as existing color as shown in the below code, 
MainWindow.cs: 
     Brush background; 
        Brush areabackground; 
        
        private async void Button_Click(object sender, RoutedEventArgs e) 
        { 
 
 
 
            background = chart.Background; 
            areabackground = chart.AreaBackground; 
 
 
            chart.Background = new SolidColorBrush(Colors.White); 
            chart.AreaBackground = new SolidColorBrush(Colors.White); 
            
            await Task.Delay(50); 
 
            chart.Save("a.png"); 
            chart.Background = background; 
            chart.AreaBackground = areabackground; 
 
        } 
 
We have prepared a demo sample for your reference and please find it from below link, 
Sample:Save_Chart 
Please let us know if you have any concerns. 
 
Regards,  
Durgadevi S 



SI Silvio August 31, 2017 02:07 PM UTC

Thank you for your help.

I tried the same your method but without using the trick of recalling the Task.Delay and it didn't work.

Recalling this method in an asyncronous way now it works!

Thank you.


Silvio Scattaglia



DS Durgadevi Selvaraj Syncfusion Team September 1, 2017 04:47 AM UTC

Hi Silvio, 
We glad to know that your problem has been resolved. 
Please let us know if you required any further assistance on this. 
Regards, 
Durgadevi S 


Loader.
Live Chat Icon For mobile
Up arrow icon