Back to Devexpress

ScaleGridOptionsBase.GridSpacing Property

corelibraries-devexpress-dot-xtracharts-dot-scalegridoptionsbase-16c98a54.md

latest10.0 KB
Original Source

ScaleGridOptionsBase.GridSpacing Property

Gets or sets the interval between grid lines and major tickmarks.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.dll

NuGet Package : DevExpress.Charts

Declaration

csharp
[XtraChartsLocalizableCategory(XtraChartsCategory.Behavior)]
public double GridSpacing { get; set; }
vb
<XtraChartsLocalizableCategory(XtraChartsCategory.Behavior)>
Public Property GridSpacing As Double

Property Value

TypeDescription
Double

The interval between grid lines and major tickmarks, in units specified by the NumericScaleOptions.GridAlignment (DateTimeScaleOptions.GridAlignment or TimeSpanScaleOptions.GridAlignment.

|

Remarks

This feature manages label placement along the axis. By default, the ScaleGridOptionsBase.AutoGrid is true , and the GridSpacing is set automatically. If you wish to change the step interval for axis labeling, specify the interval between grid alignment units by the GridSpacing property value.

It is important to note that the GridSpacing and ScaleGridOptionsBase.AutoGrid properties are interdependent - changing the value of one property affects the value of the other.

The following images demonstrate how the GridSpacing property works.

|

AutoGrid = true;

(auto) GridSpacing=1;

(auto) GridAlignment=”Week”;

(auto) MeasureUnit=”Day”;

|

AutoGrid = false;

GridSpacing=3;

GridAlignment=”Day”;

MeasureUnit=”Day”;

| | --- | --- | |

|

|

Note

If the AxisBase.Logarithmic scale is enabled, the GridSpacing property value is rounded to integer values. Note that since GridSpacing can’t be set to 0 , if its value is less than 1 (e.g., 0.1 ) it is always rounded to 1.

For more information, refer to Axis Scale Types.

Example

This example shows how to use NumericScaleOptions to reduce the number of visible series points.

The following code configures the axis scale settings to resemble to the chart appearance above:

csharp
NumericScaleOptions numericScaleOptions = ((XYDiagram)chartControl.Diagram).AxisX.NumericScaleOptions;

numericScaleOptions.ScaleMode = ScaleMode.Manual;
numericScaleOptions.MeasureUnit = NumericMeasureUnit.Hundreds;
numericScaleOptions.GridOffset = 5;
numericScaleOptions.AggregateFunction = AggregateFunction.Average;
numericScaleOptions.GridAlignment = NumericGridAlignment.Thousands;
numericScaleOptions.GridSpacing = 1;
vb
Dim numericScaleOptions As NumericScaleOptions = CType(chartControl.Diagram,XYDiagram).AxisX.NumericScaleOptions

numericScaleOptions.ScaleMode = ScaleMode.Manual
numericScaleOptions.MeasureUnit = NumericMeasureUnit.Hundreds
numericScaleOptions.GridOffset = 5
numericScaleOptions.AggregateFunction = AggregateFunction.Average
numericScaleOptions.GridAlignment = NumericGridAlignment.Thousands
numericScaleOptions.GridSpacing = 1

The following table lists the API members the code above uses:

MemberDescription
AxisBase.NumericScaleOptionsStores the options that define the behavior of a scale when its type is numeric.
ScaleOptionsBase.ScaleModeGets or sets the scale mode for an axis.
ScaleModeLists the values that specify the scale mode for an axis.
NumericScaleOptions.MeasureUnitGets or sets the detail level for numeric values.
NumericMeasureUnitLists the values that specify the detail level for numeric values.
ScaleGridOptionsBase.GridOffsetGets or sets the offset of grid lines and major tickmarks.
ScaleGridOptionsBase.AggregateFunctionGets or sets the value indicating the aggregate function that should be used to relieve data.
AggregateFunctionLists the values that specify the aggregate function used for an axis.
NumericScaleOptions.GridAlignmentGets or sets the numeric measure unit to which the beginning of an axis’ gridlines and labels should be aligned.
NumericGridAlignmentLists the values that specify the numeric-time measurement unit, to which the beginning of a diagram’s gridlines and labels should be aligned.
ScaleGridOptionsBase.GridSpacingGets or sets the interval between grid lines and major tickmarks.

The following code snippets (auto-collected from DevExpress Examples) contain references to the GridSpacing property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-charts-create-model-for-custom-chart-element/CS/CustomChartElementModel/Form1.cs#L130

csharp
diagram.AxisX.DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Hour;
diagram.AxisX.DateTimeScaleOptions.GridSpacing = 9;
diagram.AxisX.WholeRange.SideMarginsValue = 1.2;

winforms-charts-create-line-chart/CS/Series_LineChart/Form1.cs#L43

csharp
((XYDiagram)lineChart.Diagram).AxisX.NumericScaleOptions.AutoGrid = false;
((XYDiagram)lineChart.Diagram).AxisX.NumericScaleOptions.GridSpacing = 1;

winforms-charts-use-automatic-date-time-scale-modes-of-an-axis/CS/DateTimeAggregation/Form1.cs#L107

csharp
void ResetAxisOptions() {
    AxisX.DateTimeScaleOptions.GridSpacing = 1;
    AxisX.Tickmarks.MinorVisible = false;

winforms-charts-create-model-for-custom-chart-element/VB/CustomChartElementModel/Form1.vb#L188

vb
diagram.AxisX.DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Hour
diagram.AxisX.DateTimeScaleOptions.GridSpacing = 9
diagram.AxisX.WholeRange.SideMarginsValue = 1.2

winforms-charts-create-line-chart/VB/Series_LineChart/Form1.vb#L40

vb
CType(lineChart.Diagram, XYDiagram).AxisX.NumericScaleOptions.AutoGrid = False
CType(lineChart.Diagram, XYDiagram).AxisX.NumericScaleOptions.GridSpacing = 1
' Hide the legend (if necessary).

winforms-charts-use-automatic-date-time-scale-modes-of-an-axis/VB/DateTimeAggregation/Form1.vb#L94

vb
Private Sub ResetAxisOptions()
    AxisX.DateTimeScaleOptions.GridSpacing = 1
    AxisX.Tickmarks.MinorVisible = False

See Also

ScaleGridOptionsBase Class

ScaleGridOptionsBase Members

DevExpress.XtraCharts Namespace