$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
How to Put up Axes of Chart toolkit Using C#
Home > How to > Chart Axes
The element axes have been widely used in many chart types because it can not only display data values and data series but also explain the meaning of the measurement units. And the axes element has two dimensions, X and Y axis. The functions of these two axes are not fixed. But we are used to showing data values with YAxis and displaying specific categories being compared with XAxis.
Sometimes, to better compare the values of target data series, we may create two axis in y orientation: both YAxis and YAxis2 to display the value, and the dual axis can stand by different categories with different format. And the scale of measurements for YAxis and YAxis2 can be different.
This online tutorial page will put its focus on how to customize each element of the axis at your practical needs using C# code in ASP.NET web application. Please note, both 2 y axis are allowed to modify the labels, words, lines, titles, position in the web chart.

Axis Elements

Typically, each axis has five elements, which are Gridline, Axis line, Axis label, Axis marks and Item label. And in following text, we will illustrate how to set above mentioned axis elements using C# code one by one. Especially you can change these properties in the secondary y axis.

How to Set Gridline Using C# Code

To make the chart be better and easier viewed and understood, we will use some lines to form a grid. And those lines are called gridlines, showing in both vertical and horizontal. In general, we can change the gridline style by changing the PenStyle, Color and Width using MajorGridLine and MinorGridLine. Following C# code will show you how to set the gridline of Y Axis.

KaxChart1.Diagram.AxisY.StyleSet.MajorGridLines.PenStyle = System.Drawing.Drawing2D.DashStyle.Solid;
KaxChart1.Diagram.AxisY.StyleSet.MajorGridLines.Color = System.Drawing.Color.LightGreen;
KaxChart1.Diagram.AxisY.StyleSet.MajorGridLines.Width = 3;
KaxChart1.Diagram.AxisY.StyleSet.MajorGridLines.Visible = true;

KaxChart1.Diagram.AxisY.StyleSet.MinorGridLines.PenStyle = System.Drawing.Drawing2D.DashStyle.Dot;
KaxChart1.Diagram.AxisY.StyleSet.MinorGridLines.Color = System.Drawing.Color.LightGreen;
KaxChart1.Diagram.AxisY.StyleSet.MinorGridLines.Width = 2;
KaxChart1.Diagram.AxisY.StyleSet.MinorGridLines.Visible = true;

How to Set Axis Line Using C# Code

The appearance of Axis line can be fully customized by setting its color and width.

KaxChart1.Diagram.AxisY.StyleSet.Color = System.Drawing.Color.Red;
KaxChart1.Diagram.AxisY.StyleSet.Width = 5;

How to Set Axis Label Using C# Code

The axis label, a text string, can be used to explain the meaning of the units that each axis represents. And users can re-set the Axis Label style by using Appearance and TextBlock properties. Additional, you can modify the font style, offset, template, wrap mode of the chart axis label in your C# or Visual Basic web applications.
Following C# codes are used to add a XAix Lable, define its position and customize its rotating degree.

KaxChart1.Diagram.AxisX.AxisLabel.TextArea.Text = "AxisX Label Value";

KaxChart1.Diagram.AxisX.AxisLabel.TextArea.StyleSet.Position.AlignedPosition = AlignedPositions.BottomLeft;

KaxChart1.Diagram.AxisY.AxisLabel.StyleSet.RotationAngle = 75;

How to Set Axis Marks Using C# Code

The axis marks are along the axis line.

KaxChart1.Diagram.AxisX.AxisLabel.Marker.Visible = true;
KaxChart1.Diagram.AxisX.AxisLabel.Marker.StyleSet.Fill.FillMode = FillMode.Solid;
KaxChart1.Diagram.AxisX.AxisLabel.Marker.StyleSet.Fill.PrimaryColor = System.Drawing.Color.Red;

How to Set Item Label Using C# Code

Item label is a text or numeric string positioned below the axis line. The MinValue and MaxValue properties are offered to help users define the smallest and largest values that the data can be displayed. Besides, you can also customize the rotation of created item label.

KaxChart1.Diagram.AxisY.MaxValue = 5;
KaxChart1.Diagram.AxisY.MinValue = -5;
KaxChart1.Diagram.AxisY.Step = 1;

KaxChart1.Diagram.AxisY.StyleSet.LabelAppearance.RotationAngle = 75;