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.
Unfortunately, activation email could not send to your email. Please try again.

How to change SfChart background when calling the Save method

Thread ID:

Created:

Updated:

Platform:

Replies:

132390 Aug 30,2017 03:10 AM Sep 1,2017 12:47 AM WPF 3
loading
Tags: SfChart
Silvio
Asked On August 30, 2017 03:10 AM

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

Durgadevi Selvaraj [Syncfusion]
Replied On August 31, 2017 08:37 AM

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 


Silvio
Replied On August 31, 2017 10:07 AM

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


Durgadevi Selvaraj [Syncfusion]
Replied On September 1, 2017 12:47 AM

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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;