|
| 1 | +--- |
| 2 | +title: Achieving Consistent Chart Rendering Across Android and iOS |
| 3 | +description: Learn how to achieve consistent rendering for CartesianChart in .NET MAUI between Android and iOS, including fixing Y-axis line visibility and label alignment. |
| 4 | +type: how-to |
| 5 | +page_title: Fixing Y-Axis Line and Label Alignment in Chart for iOS |
| 6 | +meta_title: Fixing Y-Axis Line and Label Alignment in Chart for iOS |
| 7 | +slug: chart-ios-y-axis-label-line-visibility |
| 8 | +tags: chart,.net maui,radcartesianchart,axis,handler |
| 9 | +res_type: kb |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +| Version | Product | Author | |
| 15 | +| --- | --- | ---- | |
| 16 | +| 11.0.0 | Telerik UI for .NET MAUI Chart | [Dobrinka Yordanova](https://www.telerik.com/blogs/author/dobrinka-yordanova) | |
| 17 | + |
| 18 | +## Description |
| 19 | + |
| 20 | +I want to achieve consistent rendering for the [Chart](https://docs.telerik.com/devtools/maui/controls/chart/types/cartesian-chart) in .NET MAUI across Android and iOS. On iOS, the Y-axis line is not visible, and the axis labels are inside the chart renderer and right-aligned instead of left-aligned as on Android. |
| 21 | + |
| 22 | +This knowledge base article also answers the following questions: |
| 23 | +- How to make the Y-axis line visible in `RadCartesianChart` for iOS? |
| 24 | +- How to align the Y-axis labels to the left in `RadCartesianChart` for iOS? |
| 25 | +- How to customize the `RadCartesianChart` rendering for iOS in .NET MAUI? |
| 26 | + |
| 27 | +## Solution |
| 28 | + |
| 29 | +Access the native iOS chart control via the handler to customize the Y-axis line visibility and label alignment. |
| 30 | + |
| 31 | +1. Subscribe to the `HandlerChanged` event of `RadCartesianChart`. |
| 32 | +2. Access the native iOS control in the event handler. |
| 33 | +3. Modify the Y-axis properties to make the line visible and align the labels to the left. |
| 34 | + |
| 35 | +```csharp |
| 36 | +<telerik:RadCartesianChart x:Name="chart" /> |
| 37 | + |
| 38 | +public partial class MainPage : ContentPage |
| 39 | +{ |
| 40 | + public MainPage() |
| 41 | + { |
| 42 | + InitializeComponent(); |
| 43 | + this.BindingContext = new SeriesCategoricalViewModel(); |
| 44 | + |
| 45 | + this.chart.HandlerChanged += this.Chart_HandlerChanged; |
| 46 | + } |
| 47 | + |
| 48 | + private void Chart_HandlerChanged(object sender, EventArgs e) |
| 49 | + { |
| 50 | + this.UpdateChart(); |
| 51 | + } |
| 52 | + |
| 53 | + private void UpdateChart() |
| 54 | + { |
| 55 | + var platformView = this.chart.Handler.PlatformView; |
| 56 | +#if IOS || MACCATALYST |
| 57 | + var platformChart = (Telerik.Maui.Controls.Compatibility.ChartRenderer.iOS.TKExtendedChart)platformView; |
| 58 | + platformChart.YAxis.Style.LineHidden = false; |
| 59 | + platformChart.YAxis.Style.LabelStyle.TextAlignment = TelerikUI.TKChartAxisLabelAlignment.Left; |
| 60 | + platformChart.YAxis.Style.LabelStyle.FirstLabelTextAlignment = TelerikUI.TKChartAxisLabelAlignment.Left; |
| 61 | +#endif |
| 62 | + } |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +## See Also |
| 67 | + |
| 68 | +- [CartesianChart Overview](https://docs.telerik.com/devtools/maui/controls/chart/types/cartesian-chart) |
| 69 | +- [Customizing Native Chart Controls in .NET MAUI](https://docs.telerik.com/devtools/maui/search?q=chart) |
0 commit comments