Example E294
Visible to All Users

Chart for WinForms - How to Make Points in a Chart Control Interactively Adjustable

This example demonstrates how to allow end-users to edit (move) series points data at runtime.

Handle the ChartControl.ObjectHotTracked event and call ChartControl.XYDiagram.PointToDiagram method to convert physical coordinates of the mouse to logical.

Files to Review

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

Form1.cs(vb)
C#
using System.Windows.Forms; using DevExpress.XtraCharts; namespace ChartInteractivePoints { public partial class Form1 : Form { public Form1() { InitializeComponent(); } 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) { // Update AxisY.WholeRange if the point is too close to diagram bounds WholeRange range = ((XYDiagram)(sender as ChartControl).Diagram).AxisY.WholeRange; 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; } } }
Program.cs(vb)
C#
using System; using System.Collections.Generic; using System.Windows.Forms; namespace ChartInteractivePoints { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.