How to modify the stripline collection in Xamarin.Android Charts?
Xamarin.Android Chart allows you to shade the different ranges in the plot area using the Striplines support.
The Stripline is classified as NumericalStripLine and DateTimeStripLine based on the type of input, you can proceed to draw the Striplines. The NumericalStripLine is used to draw striplines for numerical values and the following code sample explains how to draw the NumericalStripLines and modify the stripline collection programmatically.
[C#]
LinearLayout linearLayout = new LinearLayout(this) { Orientation = Orientation.Vertical, LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent) }; chart = new SfChart(this) { PrimaryAxis = GetCategoryAxis(), SecondaryAxis = GetSecondaryAxis(), }; chart.SetPadding(20, 50, 20, 0); chart.Series.Add( new LineSeries() { ItemsSource = new ViewModel().Date, XBindingPath = "Month", YBindingPath = "Temperature", Color = Android.Graphics.Color.Red }); Spinner spinner = new Spinner(this) { Adapter = ArrayAdapter.CreateFromResource(this, Resource.Array.action_array, Android.Resource.Layout.SimpleSpinnerItem), }; spinner.SetSelection(3); spinner.ItemSelected += Spinner_ItemSelected; … linearLayout.AddView(spinner); linearLayout.AddView(chart); SetContentView(linearLayout);
[C#]
private void Spinner_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e) { var index = (sender as Spinner).SelectedItemPosition; if (index == 0) { NumericalStripLine stripLine = new NumericalStripLine() { Start = 16, Width = 3, Text = "Low Temperature", FillColor = Android.Graphics.Color.Rgb(66, 197, 245) }; (chart.SecondaryAxis as NumericalAxis).StripLines.Insert(0, stripLine); } else if (index == 1) { (chart.SecondaryAxis as NumericalAxis).StripLines.Remove((chart.SecondaryAxis as NumericalAxis).StripLines[0]); } else if (index == 2) { if ((chart.SecondaryAxis as NumericalAxis).StripLines.Count > 0) { (chart.SecondaryAxis as NumericalAxis).StripLines.RemoveAt(0); } } else if (index == 3) { NumericalStripLine stripLine = new NumericalStripLine() { Start = 28, Width = 3, Text = "High Temperature", FillColor = Android.Graphics.Color.Rgb(6, 104, 140) }; NumericalStripLine stripLine1 = new NumericalStripLine() { Start = 16, Width = 3, Text = "Low Temperature", FillColor = Android.Graphics.Color.Rgb(66, 197, 245) }; (chart.SecondaryAxis as NumericalAxis).StripLines.Add(stripLine); (chart.SecondaryAxis as NumericalAxis).StripLines.Add(stripLine1); } else if (index == 4) { (chart.SecondaryAxis as NumericalAxis).StripLines.Clear(); } }
See also
How to customize strip line label in Xamarin.Android Chart
How to draw the strip lines repeatedly at the regular intervals
How to draw a strip line without stretch with its associated axis
Conclusion
I hope you enjoyed learning about how to modify the stripline collection in Xamarin.Android Charts.
You can refer to our Xamarin.Forms Charts feature tour page to know about its other groundbreaking feature representations. You can also explore our Xamarin.Forms Charts documentation to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!