The Chart control provides the means to change axis settings at design time or run time. Chart axes make it possible to view and understand the data plotted in a graph.
Most 2D charts contain a numerical axis (AxisY) and a categorical axis (AxisX). 3D charts include another numerical axis (AxisZ). These axes are accessible at run time from the ChartArea object and allow you to control the settings for each, including scaling, labels, and various formatting properties. For any of the scaling or labeling properties you set to show up at run time, you will need to set the Visible property of the axis to True.
Axis settings can be changed at design time by clicking on a Chart control and using the Properties Window or at run time in code from the chart's ChartArea object.
For normal linear scaling on a numeric axis, set the Max and Min properties for the axis, which correspond to the numerical values in the chart's data series. Also, set the Step property of the MajorTick to show the major numerical unit values. The Step property controls where labels and tick marks are shown on the numerical axis.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the section Format event. |
Copy Code |
---|---|
With Me.ChartControl1.ChartAreas(0).Axes("AxisY") .Max = 100 .Min = 0 .MajorTick.Step = 10 End With |
To write the code in C#
C# code. Paste INSIDE the section Format event. |
Copy Code |
---|---|
this.chartControl1.ChartAreas[0].Axes["AxisY"].Max = 100; this.chartControl1.ChartAreas[0].Axes["AxisY"].Min = 0; this.chartControl1.ChartAreas[0].Axes["AxisY"].MajorTick.Step = 10; |
The Chart control also supports logarithmic scaling which allows you to show the vertical spacing between two points that corresponds to the percentage of change between those numbers. You can set your numeric axis to scale logarithmically by setting the IsLogarithmic property on the axis to True and setting the Max and Min properties of the axis.
To show labels on an axis, you will need to specify the value for the LabelsGap property, set your LabelsFont properties, and set LabelsVisible to True. These properties can be set in the AxisBase Collection editor, which is accessed at design time by clicking the ellipsis button next to the ChartAreas (Collection) property, then the Axes (Collection) property of the ChartArea.
Tip: Labels render first, and then the chart fills in the remaining area, so be sure to make the chart large enough if you use angled labels.
You can specify strings to be used for the labels instead of numerical values on an axis by using the Labels collection property at design time or assigning a string array to the Labels property at run time. You can also specify whether you want your axis labels to appear on the outside or inside of the axis line using the LabelsInside property. By default, labels appear outside the axis line.
By default, a Chart object includes secondary X and Y axes (AxisX2 and AxisY2). At design time or run time, you can specify a secondary axis to plot data against by setting all of the appropriate properties for AxisX2 or AxisY2, including the Visible property.
If you want to use two axes to show the same data as it appears on two different scales, you can set the primary axis to show the actual data value scale, for example, and set the secondary axis to show a logarithmic scale.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the section Format event. |
Copy Code |
---|---|
' set properties for AxisY (primary axis) With Me.ChartControl1.ChartAreas(0).Axes("AxisY") .Max = 25 .Min = 0 .MajorTick.Step = 5 End With ' set properties for AxisY2 (secondary Y axis) With Me.ChartControl1.ChartAreas(0).Axes("AxisY2") .Max = 1000 .Min = 0 .MajorTick.Step = 200 ' set the scaling for the secondary axis to logarithmic .AxisType = DataDynamics.ActiveReports.Chart.AxisType.Logarithmic.Visible = True End With |
To write the code in C#
C# code. Paste INSIDE the section Format event. |
Copy Code |
---|---|
// set properties for AxisY (primary axis) this.chartControl1.ChartAreas[0].Axes["AxisY"].Max = 25; this.chartControl1.ChartAreas[0].Axes["AxisY"].Min = 0; this.chartControl1.ChartAreas[0].Axes["AxisY"].MajorTick.Step = 5; // set properties for AxisY2 (secondary Y axis) this.chartControl1.ChartAreas[0].Axes["AxisY2"].Max = 1000; this.chartControl1.ChartAreas[0].Axes["AxisY2"].Min = 0; this.chartControl1.ChartAreas[0].Axes["AxisY2"].MajorTick.Step = 200; // set the axis type for the secondary axis to logarithmic this.chartControl1.ChartAreas[0].Axes["AxisY2"].AxisType = DataDynamics.ActiveReports.Chart.AxisType.Logarithmic; this.chartControl1.ChartAreas[0].Axes["AxisY2"].Visible = true; |
The Chart control supports the creation of additional custom axes through the use of the chart's CustomAxes collection. Once a custom axis has been added to the collection, in addition to setting the normal axis properties, you will need to set the following properties:
The following code sample demonstrates creating a custom axis, adding it to the Axes collection for the ChartArea, and setting its properties.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the section Format event. |
Copy Code |
---|---|
' create the custom axis and add it to the ChartArea's Axes collection Dim customAxisY As New DataDynamics.ActiveReports.Chart.CustomAxis Me.ChartControl1.ChartAreas(0).Axes.Add(customAxisY) ' set the basic axis properties for customAxisY customAxisY.LabelFont = New DataDynamics.ActiveReports.Chart.FontInfo(Color.Red, New Font("Arial", 7.0!)) customAxisY.LabelsGap = 1 customAxisY.LabelsVisible = True customAxisY.Line = New DataDynamics.ActiveReports.Chart.Graphics.Line(Color.Red) customAxisY.MajorTick = New DataDynamics.ActiveReports.Chart.Tick(New DataDynamics.ActiveReports.Chart.Graphics.Line(Color.Red, 1), New DataDynamics.ActiveReports.Chart.Graphics.Line(Color.Red, 1), 1, 2.0F, True) customAxisY.MajorTick.GridLine = New DataDynamics.ActiveReports.Chart.Graphics.Line(Color.Red, 1, LineStyle.Solid) customAxisY.MajorTick.Visible = True customAxisY.Max = 5 customAxisY.MaxDerived = False customAxisY.Min = 0 customAxisY.Visible = True ' set the special custom axis properties customAxisY.Parent = ((CType(Me.ChartControl1.ChartAreas(0).Axes("AxisY"), DataDynamics.ActiveReports.Chart.Axis))) customAxisY.PlacementLength = 20 customAxisY.PlacementLocation = 30 |
To write the code in C#
C# code. Paste INSIDE the section Format event. |
Copy Code |
---|---|
// create the custom axis and add it to the ChartArea's Axes collection DataDynamics.ActiveReports.Chart.CustomAxis customAxisY = new DataDynamics.ActiveReports.Chart.CustomAxis(); this.chartControl1.ChartAreas[0].Axes.Add(customAxisY); // set the basic axis properties for customAxisY customAxisY.LabelFont = new DataDynamics.ActiveReports.Chart.FontInfo(Color.Red, new Font("Arial", 7F, FontStyle.Regular, GraphicsUnit.Point, ((System.Byte)(0)))); customAxisY.LabelsGap = 1; customAxisY.LabelsVisible = true; customAxisY.Line = new DataDynamics.ActiveReports.Chart.Graphics.Line(Color.Red); customAxisY.MajorTick = new DataDynamics.ActiveReports.Chart.Tick(new DataDynamics.ActiveReports.Chart.Graphics.Line(Color.Red, 1), new DataDynamics.ActiveReports.Chart.Graphics.Line(Color.Red, 1), 1, 2F, true); customAxisY.MajorTick.GridLine = new DataDynamics.ActiveReports.Chart.Graphics.Line(Color.Red, 1, LineStyle.Solid); customAxisY.MajorTick.Visible = true; customAxisY.Max = 5; customAxisY.MaxDerived = false; customAxisY.Min = 0; customAxisY.Visible = true; // set the special custom axis properties customAxisY.Parent = (DataDynamics.ActiveReports.Chart.Axis)this.ChartControl1.ChartAreas[0].Axes["AxisY"]; customAxisY.PlacementLength = 20; customAxisY.PlacementLocation = 30; |
Gridlines and tick marks are generally used to help increase the readability of a chart.
There are two kinds of gridlines and tick marks in the Chart control: major and minor. The properties for the major gridlines and tick marks are set on the MajorTick object of the particular axis and the properties for minor gridlines and ticks are set on the MinorTick object of the axis. The location for any labels shown for the axis are determined by the Step property of the MajorTick object.
For either the MajorTick or MinorTick objects, you can define where the tick marks and gridlines will appear by setting the Step property. The TickLength property allows you to set how far outside of the axis line the tick mark will extend.
To make any defined major or minor tick marks to show up at design time or run time, the Visible property of the MajorTick or MinorTick object must be set to True. To show major or minor gridlines at design time or run time, the Visible property of the WallXY object as well as that of the MajorTick or MinorTick object must be set to True.