New to Telerik UI for WinForms? Download free 30-day trial

Axes

Each RadChartView area type uses a different set of axes to plot its data points. For example, Cartesian Area supports the following axes: Categorical, Linear, Logarithmic, DateTimeCategorical and DateTimeContinuous. Polar area, however, renders its data upon Polar and Radar axes only. Note that Pie area does not support axes. This article discusses the common characteristics of the abstract class Axis, which is the single class all RadChartView axes derive from. This class is responsible for displaying major and minor ticks and rendering the labels associated with the ticks. It also introduces several important properties:

  • AxisType: The property sets the axis to be either First or Second.

  • LabelFitMode: Gets or sets a value that determines how the axis labels will be laid out when they overlap. The property specifies the approach the axis will use to handle label collision. The possible fit modes are None, Multiline and Rotate. None renders the all labels at their specified location without applying any fit logic. Multiline displays labels on a number of rows and Rotate turns the labels around a fixed point. Note that Multiline mode repositions the labels only if it is needed, while Rotate affects the labels regardless of the available space.

  • LabelRotationAngle: Gets or sets the rotation angle of the labels when LabelFitMode equals Rotate.

  • LabelFormat: Applies a predefined format to the label contents.

  • LabelFormatProvider: Supplies an object that provides formatting information.

  • LabelInterval: Gets or sets the step at which labels are positioned. Specifies the value indicating that only the first out of n-axis labels is visible, where n is the value of the property. Setting the value to 2 makes every second label disappear and setting it to 3 makes only the first of each three labels visible.

  • LabelOffset: Gets or sets index-based offset of the first tick to be displayed. Setting this property to 1 makes the first label disappear; setting it to 3 makes the first three labels hidden. Note that the property only hides the labels. To hide the ticks use MajorTickOffset property.

  • LastLabelVisibility: Specifies whether the last label should be Clipped, Visible or Hidden.

  • LineWidth: The property specifies the width of the axis.

  • MajorTickOffset: Gets or sets index-based offset of the first tick to be displayed.

  • TickLength: Gets or sets the length of major ticks.

  • TickWidth: Gets or sets the thickness of a single tick present on the axis.

  • Title: Specifies the title of the axis.

  • ShowLabels: A Boolean property that indicates whether the labels will be rendered or hidden.

  • BorderColor: The property sets the color used to draw the axis and the ticks

  • ForeColor: Determines the color used to render the labels of the axis

  • BorderWidth: The property specifies the width of the axis

  • EnableElementCache: Determines whether the axis labels will be cached or not.

The EnableElementCache property is by default set to true. In scenarios requiring frequent updates in the chart`s data points it is recommended to set the property to false.

Figure 1: Axes Types

WinForms RadChartView Axes Types

The following example demonstrates how some of the above properties are set:

Set Properties

BarSeries series = new BarSeries();
series.DataPoints.Add(new CategoricalDataPoint(10, "First"));
series.DataPoints.Add(new CategoricalDataPoint(30, "Second"));
series.DataPoints.Add(new CategoricalDataPoint(22, "Third"));
series.DataPoints.Add(new CategoricalDataPoint(15, "Fourth"));
series.DataPoints.Add(new CategoricalDataPoint(40, "Fifth"));
series.DataPoints.Add(new CategoricalDataPoint(80, "Sixth"));
this.radChartView1.Series.Add(series);
CategoricalAxis categoricalAxis = radChartView1.Axes[0] as CategoricalAxis;
categoricalAxis.PlotMode = AxisPlotMode.OnTicksPadded;
categoricalAxis.LabelFitMode = AxisLabelFitMode.Rotate;
categoricalAxis.LabelRotationAngle = 310;
LinearAxis verticalAxis = radChartView1.Axes[1] as LinearAxis;
verticalAxis.ForeColor = Color.Green;
verticalAxis.BorderColor = Color.DarkOrange;
verticalAxis.MajorStep = 10;
verticalAxis.Maximum = 100;
verticalAxis.Minimum = 0;
verticalAxis.LabelInterval = 2;
verticalAxis.LabelFormat = "{0:c}";

Dim series As New BarSeries()
series.DataPoints.Add(New CategoricalDataPoint(10, "First"))
series.DataPoints.Add(New CategoricalDataPoint(30, "Second"))
series.DataPoints.Add(New CategoricalDataPoint(22, "Third"))
series.DataPoints.Add(New CategoricalDataPoint(15, "Fourth"))
series.DataPoints.Add(New CategoricalDataPoint(40, "Fifth"))
series.DataPoints.Add(New CategoricalDataPoint(80, "Sixth"))
Me.RadChartView1.Series.Add(series)
Dim categoricalAxis As CategoricalAxis = TryCast(RadChartView1.Axes(0), CategoricalAxis)
categoricalAxis.PlotMode = AxisPlotMode.OnTicksPadded
categoricalAxis.LabelFitMode = AxisLabelFitMode.Rotate
categoricalAxis.LabelRotationAngle = 310
Dim verticalAxis As LinearAxis = TryCast(RadChartView1.Axes(1), LinearAxis)
verticalAxis.ForeColor = Color.Green
verticalAxis.BorderColor = Color.DarkOrange
verticalAxis.MajorStep = 10
verticalAxis.Maximum = 100
verticalAxis.Minimum = 0
verticalAxis.LabelInterval = 2
verticalAxis.LabelFormat = "{0:c}"

Having the BorderColor property of the axis set to a color different than the one defined in the theme will also set the border color of the axis labels. As this might not be desired one can access each of the labels and explicitly set their BorderColor to Transparent. A suitable place for this is the Shown event of the form

Labels Border Color

private void AxisForm_Shown(object sender, EventArgs e)
{
    LinearAxis verticalAxis = (LinearAxis)this.radChartView1.Axes[1];
    foreach (var item in verticalAxis.Children)
    {
        AxisLabelElement labelElement = item as AxisLabelElement;
        if (labelElement != null)
        {
            labelElement.BorderColor = Color.Transparent;
        }
    }
}

Private Sub AxisForm_Shown(sender As Object, e As EventArgs)
    Dim verticalAxis As LinearAxis = CType(Me.RadChartView1.Axes(1), LinearAxis)
    For Each item In verticalAxis.Children
        Dim labelElement As AxisLabelElement = TryCast(item, AxisLabelElement)
        If labelElement IsNot Nothing Then
            labelElement.BorderColor = Color.Transparent
        End If
    Next
End Sub

Figure 2: Property Settings

WinForms RadChartView Property Settings

See Also

In this article