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;
}
Tip
A complete sample project is available in the DevExpress Code Examples database at https://supportcenter.devexpress.com/ticket/details/e294/chart-for-winforms-how-to-make-points-in-a-chart-control-interactively-adjustable.
See Also