Back to Devexpress

ManualDateTimeScaleOptions.GridSpacing Property

wpf-devexpress-dot-xpf-dot-charts-dot-manualdatetimescaleoptions-ebd754cf.md

latest8.4 KB
Original Source

ManualDateTimeScaleOptions.GridSpacing Property

Gets or sets the date-time grid step in grid alignment units.

Namespace : DevExpress.Xpf.Charts

Assembly : DevExpress.Xpf.Charts.v25.2.dll

NuGet Package : DevExpress.Wpf.Charts

Declaration

csharp
public double GridSpacing { get; set; }
vb
Public Property GridSpacing As Double

Property Value

TypeDescription
Double

A Double value which specifies the date-time grid step.

|

Remarks

This property manages label placement along the X-axis.

By default, the GridSpacing is set to the default value, so the grid step is calculated automatically. To change the grid step interval for axis labeling, set the ManualDateTimeScaleOptions.AutoGrid to false , and specify the GridSpacing property value.

The table below shows the GridSpacing property in action for random data.

ManualDateTimeScaleOptions.GridSpacing = 2ManualDateTimeScaleOptions.GridSpacing = 4

Example

This example uses manual date-time scale options of the X-axis. It sets the AxisX2D.DateTimeScaleOptions property to ManualDateTimeScaleOptions and specifies GridAlignment, MeasureUnit, and AggregateFunction properties.

This example obtains data from the GbpUsdRate.xml file. Download GbpUsdRate.xml

xaml
<dx:ThemedWindow
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
    xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts" 
    x:Class="DXWPFCharts.MainWindow"
    Title="MainWindow" Height="800" Width="1000">
    <Grid>
        <dxc:ChartControl>
            <dxc:XYDiagram2D >
                <dxc:XYDiagram2D.AxisX>
                    <dxc:AxisX2D GridLinesMinorVisible="True" GridLinesVisible="True" MinorCount="3">
                        <dxc:AxisX2D.Title>
                            <dxc:AxisTitle Content="Date"/>
                        </dxc:AxisX2D.Title>
                        <dxc:AxisX2D.DateTimeScaleOptions>
                            <dxc:ManualDateTimeScaleOptions AggregateFunction="Maximum" AutoGrid="False"
                                                            GridAlignment="Month" MeasureUnit="Day" 
                                                            GridSpacing="3" GridOffset="1"/>
                        </dxc:AxisX2D.DateTimeScaleOptions>
                    </dxc:AxisX2D>
                </dxc:XYDiagram2D.AxisX>
                <dxc:LineSeries2D DataSource="{Binding Path=Rate}" 
                                  ArgumentDataMember="Argument" ValueDataMember="Value" />
            </dxc:XYDiagram2D>
        </dxc:ChartControl>
    </Grid>
</dx:ThemedWindow>
csharp
using DevExpress.Xpf.Core;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Xml.Linq;

namespace DXWPFCharts {
    public partial class MainWindow : ThemedWindow {
        public MainWindow() {
            InitializeComponent();
            DataContext = new MyModel();
        }
    }
    public class DateTimePoint {
        double value;
        DateTime argument;

        public double Value {
            get { return value; }
        }

        public DateTime Argument {
            get { return argument; }
        }

        public DateTimePoint(DateTime argument, double value) {
            this.argument = argument;
            this.value = value;
        }
    }

    public class MyModel {
        List<DateTimePoint> rate = new List<DateTimePoint>();

        public List<DateTimePoint> Rate {
            get { return rate; }
        }

        public MyModel() {
            LoadPoints(rate, LoadFromFile("GbpUsdRate.xml"));
        }

        XDocument LoadFromFile(string xmlFile) {
            return XDocument.Load(xmlFile);
        }

        void LoadPoints(List<DateTimePoint> rate, XDocument document) {
            if (rate != null && document != null) {
                foreach (XElement element in document.Descendants("CurrencyRate")) {
                    DateTime argument = DateTime.Parse(element.Element("DateTime").Value);
                    double value = double.Parse(element.Element("Rate").Value, CultureInfo.InvariantCulture);
                    rate.Add(new DateTimePoint(argument, value));
                }
            }
        }
    }
}
vb
Imports DevExpress.Xpf.Core
Imports System
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Xml.Linq

Namespace DXWPFCharts
    Public Class MainWindow
        Inherits ThemedWindow

        Public Sub New()
            InitializeComponent()
            DataContext = New MyModel()
        End Sub
    End Class

    Public Class DateTimePoint
        Private value As Double
        Private argument As DateTime

        Public ReadOnly Property Value As Double
            Get
                Return value
            End Get
        End Property

        Public ReadOnly Property Argument As DateTime
            Get
                Return argument
            End Get
        End Property

        Public Sub New(argument As DateTime, value As Double)
            Me.argument = argument
            Me.value = value
        End Sub
    End Class

    Public Class MyModel
        Private rate As List(Of DateTimePoint)

        Public ReadOnly Property Rate As List(Of DateTimePoint)
            Get
                Return rate
            End Get
        End Property

        Public Sub New()
            rate = New List(Of DateTimePoint)()
            LoadPoints(rate, LoadFromFile("GbpUsdRate.xml"))
        End Sub

        Private Function LoadFromFile(xmlFile As String) As XDocument
            Return XDocument.Load(xmlFile)
        End Function

        Private Sub LoadPoints(rate As List(Of DateTimePoint), document As XDocument)
            If rate IsNot Nothing AndAlso document IsNot Nothing Then
                For Each element As XElement In document.Descendants("CurrencyRate")
                    Dim argument As DateTime = DateTime.Parse(element.Element("DateTime").Value)
                    Dim value As Double = Double.Parse(element.Element("Rate").Value, CultureInfo.InvariantCulture)
                    rate.Add(New DateTimePoint(argument, value))
                Next
            End If
        End Sub
    End Class
End Namespace

Tip

To use automatic date-time scale options, set the AxisX2D.DateTimeScaleOptions property to AutomaticDateTimeScaleOptions and select the appropriate AutomaticDateTimeScaleOptions.AggregateFunction.

See Also

ManualDateTimeScaleOptions Class

ManualDateTimeScaleOptions Members

DevExpress.Xpf.Charts Namespace