Glossary Item Box
SharpGraph 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 SharpGraph control and using the Properties grid to access the ChartAreas Collection Editor in which the AxisBase Collection is contained or the settings can be changed at run time in code from the graph's ChartArea object.

For normal linear scaling on a numeric axis, you will need to set the Max and Min properties for the axis, which correspond to the numerical values in the chart's data series. You will also need to set the Step property of the MajorTick to show the major numerical unit values. The Step property controls where labels and/or tick marks are shown on the numerical axis.
' Visual Basic
With Me.SharpGraph1.ChartAreas(0).Axes("AxisY")
.Max = 100
.Min = 0
.MajorTick.Step = 10
End With
// C#
this.sharpGraph1.ChartAreas[0].Axes["AxisY"].Max = 100;
this.sharpGraph1.ChartAreas[0].Axes["AxisY"].Min = 0;
this.sharpGraph1.ChartAreas[0].Axes["AxisY"].MajorTick.Step = 10;
SharpGraph 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 AxisType property for that axis to Logarithmic 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. 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 or not 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 of the axis line.
By default, a SharpGraph 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 wanted to use two axes to show the same data as it appears on two different scales, you could set the primary axis to show the actual data value scale, for example, and set the secondary axis to show a logarithmic scale.
' Visual Basic
Imports DataDynamics.Sharpgraph.Graphics
...
'sets properties for AxisY (primary axis)
With Me.SharpGraph1.ChartAreas(0).Axes("AxisY")
.Max = 25
.Min = 0
.MajorTick.Step = 5
End With
' set properties for AxisY2 (secondary Y axis)
With Me.SharpGraph1.ChartAreas(0).Axes("AxisY2")
.Visible = True
.Line.Style = LineStyle.Solid
.Line.Weight = 1
.Line.Color = Color.White
.LabelsVisible = True
.LabelsGap = 1
.LabelFont.Color = Color.White
.MajorTick.Visible = True
.Max = 1000
.Min = 0
.MajorTick.Step = 200
' set the scaling for the secondary axis to logarithmic
.AxisType = DataDynamics.SharpGraph.Windows.AxisType.Logarithmic
End With
// C#using DataDynamics.Sharpgraph.Graphics; ... // set properties for AxisY (primary axis) this.sharpGraph1.ChartAreas[0].Axes["AxisY"].Max = 25; this.sharpGraph1.ChartAreas[0].Axes["AxisY"].Min = 0; this.sharpGraph1.ChartAreas[0].Axes["AxisY"].MajorTick.Step = 5; // set properties for AxisY2 (secondary Y axis) this.sharpGraph1.ChartAreas[0].Axes["AxisY2"].Visible = true; this.sharpGraph1.ChartAreas[0].Axes["AxisY2"].Line.Style = LineStyle.Solid; this.sharpGraph1.ChartAreas[0].Axes["AxisY2"].Line.Weight = 1; this.sharpGraph1.ChartAreas[0].Axes["AxisY2"].Line.Color = Color.White; this.sharpGraph1.ChartAreas[0].Axes["AxisY2"].LabelsVisible = true; this.sharpGraph1.ChartAreas[0].Axes["AxisY2"].LabelsGap = 1; this.sharpGraph1.ChartAreas[0].Axes["AxisY2"].LabelFont.Color = Color.White; this.sharpGraph1.ChartAreas[0].Axes["AxisY2"].MajorTick.Visible = true; this.sharpGraph1.ChartAreas[0].Axes["AxisY2"].Max = 1000; this.sharpGraph1.ChartAreas[0].Axes["AxisY2"].Min = 0; this.sharpGraph1.ChartAreas[0].Axes["AxisY2"].MajorTick.Step = 200; // set the axis type for the secondary axis to logarithmic this.sharpGraph1.ChartAreas[0].Axes["AxisY2"].AxisType = AxisType.Logarithmic;
| See Also |
Custom Axes | Gridlines and Tick Marks
Copyright © 2006 Data Dynamics, Ltd. All rights reserved.