Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Provide Interactive Editing for Series Points

  • 2 minutes to read

This example describes how to make points in a ChartControl adjustable interactively. The key principals of this example include handling the ChartControl.ObjectHotTracked event and using the XYDiagram2D.PointToDiagram method to convert physical coordinates of the mouse to logical.

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

static int lastY = -1;
static bool isPressed = false;
static SeriesPoint selectedPoint = null;

private void chartControl1_ObjectHotTracked(object sender, HotTrackEventArgs e) {
    if(e.HitInfo.SeriesPoint != null)
        selectedPoint = e.HitInfo.SeriesPoint;

    if(selectedPoint != null && isPressed) {
        DiagramCoordinates point = 
            ((XYDiagram)(sender as ChartControl).Diagram).PointToDiagram(e.HitInfo.HitPoint);

        if(lastY != -1) {
            AxisRange range = ((XYDiagram)(sender as ChartControl).Diagram).AxisY.Range;
            double delta = ((double)range.MaxValue - (double)range.MinValue) / 8;

            if(selectedPoint.Values[0] >= (double)range.MaxValue - delta)
                range.MaxValue = selectedPoint.Values[0] + delta;

            selectedPoint.Values[0] = point.NumericalValue;

            if(point.QualitativeArgument != "")
                selectedPoint.Argument = point.QualitativeArgument;
        }

        ((ChartControl)sender).RefreshData();
        lastY = e.HitInfo.HitPoint.Y;
        return;
    }

    lastY = -1;
}

private void chartControl1_MouseDown(object sender, MouseEventArgs e) {
    isPressed = true;
}

private void chartControl1_MouseUp(object sender, MouseEventArgs e) {
    isPressed = false;
}

private void chartControl1_MouseLeave(object sender, EventArgs e) {
    isPressed = false;
}
See Also