Skip to main content

DiagramCoordinates.DateTimeArgument Property

Gets the date-time argument of the diagram point.

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v24.2.dll

Declaration

public DateTime DateTimeArgument { get; }

Property Value

Type Description
DateTime

A DateTime value, representing the diagram point’s argument.

Remarks

Use the XYDiagram2D.PointToDiagram method to convert the display coordinates of the point within the diagram to a DiagramCoordinates object. The DateTimeArgument property returns a date-time argument value if the DiagramCoordinates.ArgumentScaleType is ScaleType.DateTime. Otherwise, it returns null (Nothing in Visual Basic).

Example

The following example illustrates use of XYDiagram2D.PointToDiagram method for dragging the constant line with the mouse, and changing the series point values accordingly.

using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;

namespace InteractiveConstantLine {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        Cursor defCursor;
        bool dragging = false;
        ChartControl chart;
        XYDiagram diagram;
        ConstantLine line;

        private void Form1_Load(object sender, EventArgs e) {
            this.chart = this.chartControl1;
            this.diagram = this.chart.Diagram as XYDiagram;
            this.line = this.diagram.AxisX.ConstantLines.GetConstantLineByName("ConstantLine1");

            // Add a title to the chart.
            ChartTitle chartTitle1 = new ChartTitle();
            chartTitle1.Text = "Drag the constant line...";
            this.chart.Titles.Add(chartTitle1);

        }

        private void chartControl1_MouseDown(object sender, MouseEventArgs e) {
            if (diagram == null)
                return;

            // Get the information about the clicked point.
            DiagramCoordinates coords = diagram.PointToDiagram(e.Location);

            // If the point is within the diagram and in the constant line ...
            if (!coords.IsEmpty && line.AxisValue is DateTime &&
                coords.DateTimeArgument.Equals((DateTime)line.AxisValue)) {

                // Allow dragging, catch the mouse and change the cursor.
                dragging = true;
                chart.Capture = true;
                SetCursor();
            }
        }

        private void chartControl1_MouseUp(object sender, MouseEventArgs e) {
            dragging = false;
            chart.Capture = false;
        }

        private void chartControl1_MouseMove(object sender, MouseEventArgs e) {
            if (diagram == null)
                return;

            if (dragging && (e.Button & MouseButtons.Left) == 0) {
                dragging = false;
                chart.Capture = false;
            }

            DiagramCoordinates coords = diagram.PointToDiagram(e.Location);
            if (coords.IsEmpty)
                RestoreCursor();
            else {
                if (dragging)
                    line.AxisValue = coords.DateTimeArgument;

                if (line.AxisValue is DateTime && coords.DateTimeArgument.Equals((DateTime)line.AxisValue))
                    SetCursor();
                else
                    RestoreCursor();
            }
        }
        void SetCursor() {
            if (defCursor == null)
                defCursor = Cursor.Current;
            Cursor.Current = Cursors.VSplit;
        }

        void RestoreCursor() {
            if (defCursor != null) {
                Cursor.Current = defCursor;
                defCursor = null;
            }
        }

    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the DateTimeArgument 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.

See Also