You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+97-45Lines changed: 97 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
This article explains how to change the color of the axis elements in the [.NET MAUI charts](https://www.syncfusion.com/maui-controls/maui-charts).
4
4
5
-
The MAUI Cartesian chart provides support to customize the color of axis elements with the help of the [LabelStyle](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartAxis.html?tabs=tabid-1#Syncfusion_Maui_Charts_ChartAxis_LabelStyle), [AxisLineStyle](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartAxis.html?tabs=tabid-1#Syncfusion_Maui_Charts_ChartAxis_AxisLineStyle), [MajorGridLineStyle](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartAxis.html#Syncfusion_Maui_Charts_ChartAxis_MajorGridLineStyle), [MinorGridLineStyle](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.RangeAxisBase.html#Syncfusion_Maui_Charts_RangeAxisBase_MinorGridLineStyle), [MajorTickStyle](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartAxis.html#Syncfusion_Maui_Charts_ChartAxis_MajorTickStyle), and [MinorTickStyle](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.RangeAxisBase.html#Syncfusion_Maui_Charts_RangeAxisBase_MinorTickStyle) properties in the chart axis as shown in the following code example.
5
+
The MAUI Cartesian chart provides support to customize the color of axis elements with the help of the [LabelStyle](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartAxis.html?tabs=tabid-1#Syncfusion_Maui_Charts_ChartAxis_LabelStyle), [AxisLineStyle](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartAxis.html?tabs=tabid-1#Syncfusion_Maui_Charts_ChartAxis_AxisLineStyle), [MajorGridLineStyle](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartAxis.html#Syncfusion_Maui_Charts_ChartAxis_MajorGridLineStyle), [MinorGridLineStyle](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.RangeAxisBase.html#Syncfusion_Maui_Charts_RangeAxisBase_MinorGridLineStyle), [MajorTickStyle](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartAxis.html#Syncfusion_Maui_Charts_ChartAxis_MajorTickStyle), [MinorTickStyle](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.RangeAxisBase.html#Syncfusion_Maui_Charts_RangeAxisBase_MinorTickStyle), and [CrossesAt](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartAxis.html#Syncfusion_Maui_Charts_ChartAxis_CrossesAt) properties in the chart axis as shown in the following code example.
6
6
7
7
**[XAML]**
8
8
```
@@ -11,38 +11,61 @@ The MAUI Cartesian chart provides support to customize the color of axis element
11
11
<viewModel:ViewModel />
12
12
</chart:SfCartesianChart.BindingContext>
13
13
14
+
<!--Initializing new style for the axis line, grid lines, tick lines and labels.-->
@@ -53,48 +76,77 @@ var chart = new SfCartesianChart();
53
76
ViewModel viewModel = new ViewModel();
54
77
55
78
//Initializing new style for the axis line, grid lines, tick lines and labels.
56
-
var xAxisLableStyle = new ChartAxisLabelStyle { TextColor = Colors.Red };
57
-
var yAxisLableStyle = new ChartAxisLabelStyle { TextColor = Colors.Blue };
79
+
var xAxisLabelStyle = new ChartAxisLabelStyle { LabelFormat = "HH" };
80
+
var xAxisTitle = new ChartAxisTitle { Text = "Time in hours" };
81
+
var yAxis1LableStyle = new ChartAxisLabelStyle { TextColor = Colors.Blue, LabelFormat = "0rpm" };
82
+
var yAxis2LableStyle = new ChartAxisLabelStyle { TextColor = Colors.Green, LabelFormat = "0psi" };
58
83
var majorLineStyle = new ChartLineStyle { Stroke = Colors.Gray };
59
84
var minorLineStyle = new ChartLineStyle { Stroke = Colors.Gray, StrokeDashArray = new DoubleCollection() { 2, 2 } };
60
85
var majorTickStyle = new ChartAxisTickStyle { Stroke = Colors.Gray };
61
-
var xAxisTitle = new ChartAxisTitle() { Text = "Brand", TextColor = Colors.Red,};
62
-
var yAxisTitle = new ChartAxisTitle() { Text = " Number of items sold", TextColor = Colors.Blue,};
86
+
var yAxis1LineStyle = new ChartLineStyle { Stroke = Colors.Blue };
87
+
var yAxis2LineStyle = new ChartLineStyle { Stroke = Colors.Green };
63
88
64
89
//Initializing XAxes
65
-
var xAxis = new CategoryAxis()
90
+
var xAxis = new DateTimeAxis()
66
91
{
67
-
LabelStyle = xAxisLableStyle,
68
-
Title = xAxisTitle,
69
-
ShowMajorGridLines = false,
92
+
LabelStyle = xAxisLabelStyle,
93
+
Title = xAxisTitle,
94
+
ShowMajorGridLines = false,
70
95
};
71
96
chart.XAxes.Add(xAxis);
72
97
73
98
//Initializing YAxes
74
-
var yAxis = new NumericalAxis()
99
+
var yAxis1 = new NumericalAxis()
75
100
{
76
-
MinorTicksPerInterval = 2,
77
-
LabelStyle = yAxisLableStyle,
101
+
Name = "yAxis1",
102
+
Minimum = 0, Maximum = 6000, Interval = 1000,
103
+
MinorTicksPerInterval = 2,
104
+
LabelStyle = yAxis1LableStyle,
78
105
MajorGridLineStyle = majorLineStyle,
79
106
MinorGridLineStyle = minorLineStyle,
80
107
MajorTickStyle = majorTickStyle,
81
-
Title = yAxisTitle,
108
+
AxisLineStyle = yAxis1LineStyle,
82
109
};
83
-
chart.YAxes.Add(yAxis);
84
110
85
-
var series = new ColumnSeries()
111
+
var yAxis2 = new NumericalAxis()
86
112
{
87
-
ItemsSource = viewModel.Data,
88
-
XBindingPath = "XValue",
89
-
YBindingPath = "YValue",
113
+
Name = "yAxis2",
114
+
Minimum = 55, Maximum = 85, Interval = 5,
115
+
AxisLineStyle = yAxis2LineStyle,
116
+
LabelStyle = yAxis2LableStyle,
117
+
ShowMajorGridLines = false,
118
+
CrossesAt = double.MaxValue,
90
119
};
91
120
92
-
chart.Series.Add(series);
121
+
chart.YAxes.Add(yAxis1);
122
+
chart.YAxes.Add(yAxis2);
123
+
124
+
var series1 = new LineSeries()
125
+
{
126
+
ItemsSource = viewModel.Data,
127
+
XBindingPath = "Time",
128
+
YBindingPath = "Speed",
129
+
Label = "Speed",
130
+
Fill = Colors.Blue
131
+
};
132
+
133
+
var series2 = new LineSeries()
134
+
{
135
+
ItemsSource = viewModel.Data,
136
+
XBindingPath = "Time",
137
+
YBindingPath = "Pressure",
138
+
Label = "Pressure",
139
+
Fill = Colors.Green,
140
+
YAxisName = "yAxis2"
141
+
};
142
+
143
+
chart.Series.Add(series1);
144
+
chart.Series.Add(series2);
145
+
146
+
this.Content = chart;
93
147
94
148
```
95
149
96
-

150
+

97
151
98
152
This user guide [Documentation](https://help.syncfusion.com/maui/cartesian-charts/getting-started) helps you to acquire more knowledge on the MAUI cartesian charts and their features. You can also refer to the [Feature Tour](https://www.syncfusion.com/maui-controls/maui-charts) site to get an overview of all the features in the chart.
99
-
100
-
KB article - [How to change the color of axis elements in .NET MAUI Chart (SfCartesianChart)?]()
0 commit comments