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
- Form1.cs (VB: Form1.vb)
- Program.cs (VB: Program.vb)
Documentation
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
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;
}
}
}
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());
}
}
}