public interface IChartDependencyService
{
List<Color> GetColors(SfChart chart);
}
private void GetColors_Clicked(object sender, EventArgs e)
{
List<Color> colors = DependencyService.Get<IChartDependencyService>().GetColors(Chart);
} |
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);
}
} |
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);
}
} |
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);
}
} |