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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Get default color

Thread ID:

Created:

Updated:

Platform:

Replies:

141502 Dec 14,2018 10:32 AM UTC Dec 16,2018 05:37 AM UTC Xamarin.Forms 1
loading
Tags: SfChart
Geraschenko
Asked On December 14, 2018 10:32 AM UTC

How can  get default color from LineSeries? 
Line is colorful, but in LineSeries color and colorModel is not set.

Geetha Rajendran [Syncfusion]
Replied On December 16, 2018 05:37 AM UTC

Hi Geraschenko, 
  
Greetings from Syncfusion, 
  
You can get the default color of series by using Dependency services. Please refer the below code snippet. 
  
Code snippet [C#] – Portable 
public interface IChartDependencyService 
{ 
   List<Color> GetColors(SfChart chart); 
} 
  
private void GetColors_Clicked(object sender, EventArgs e) 
{ 
  List<Color> colors = DependencyService.Get<IChartDependencyService>().GetColors(Chart); 
} 
  
Code snippet [C#] – Android 
    public class AndroidDependencyService : IChartDependencyService 
    { 
        public List<Color> GetColors(SfChart chart) 
        { 
            var nativeChart = SfChartRenderer.GetNativeObject(typeof(SfChart), chart) as native.SfChart; 
            List<Android.Graphics.Color> colorCollection = nativeChart.ColorModel.GetColors(nativeChart.ColorModel.ColorPalette); 
            List<Color> colors= new List<Color>(); 
  
            foreach(var color in colorCollection) 
            { 
               colors.Add(GetFormsColor(color));                  
            } 
  
            return colors; 
        } 
  
        internal static Color GetFormsColor(Android.Graphics.Color color) 
        { 
            return Color.FromRgba(color.R, color.G, color.B, color.A); 
        } 
    } 
  
Code snippet [C#] – iOS 
    Public class iOSDependencyService : IChartDependencyService 
    { 
        public List<Color> GetColors(SfChart chart) 
        { 
            var nativeChart = SfChartRenderer.GetNativeObject(typeof(SfChart), chart) as native.SFChart; 
            List<UIColor> colorCollection = nativeChart.ColorModel.GetColors(nativeChart.ColorModel.Palette); 
            List<Color> colors = new List<Color>(); 
  
            foreach (var color in colorCollection) 
            { 
                colors.Add(GetFormsColor(color)); 
            } 
  
            return colors; 
        } 
  
        internal static Color GetFormsColor(UIColor color) 
        { 
            if (color == null) 
            { 
                return Color.Default; 
            } 
  
            float red = 0.0f; 
            float green = 0.0f; 
            float blue = 0.0f; 
            float alpha = 0.0f; 
            CGColor colorRef = color.CGColor; 
            nfloat[] RGBAcomponents = colorRef.Components; 
  
            if (RGBAcomponents.Count() < 4) 
            { 
                return Color.Default; 
            } 
  
            red = (float)RGBAcomponents[0]; 
            green = (float)RGBAcomponents[1]; 
            blue = (float)RGBAcomponents[2]; 
            alpha = (float)RGBAcomponents[3]; 
  
            return Color.FromRgba(red, green, blue, alpha); 
        } 
    } 
  
Code snippet [C#] – UWP 
    public class UWPDependencyService : IChartDependencyService 
    { 
        public List<Color> GetColors(SfChart chart) 
        { 
            var nativeChart = SfChartRenderer.GetNativeObject(typeof(SfChart), chart) as native.SfChart; 
            List<Brush> brushes = nativeChart.ColorModel.GetBrushes(nativeChart.Palette); 
            List<Color> colors = new List<Color>(); 
  
            foreach (var brush in brushes) 
            { 
                colors.Add(GetFormsColor((brush as SolidColorBrush).Color)); 
            } 
  
            return colors; 
        } 
  
        internal static Xamarin.Forms.Color GetFormsColor(Windows.UI.Color color) 
        { 
           return Xamarin.Forms.Color.FromRgba(color.R, color.G, color.B, color.A); 
        } 
    } 
  
  
Regards, 
Geetha R. 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

;