Articles in this section
Category / Section

How to drag and drop the chart series points at run time?

1 min read

 

We can drop and drag the chart series points by calculating new X and Y values while doing any ChartRegionMouse Events like MouseUp, MouseDown, MouseHover, MouseLeave on the chart. The series new X and Y values are calculated from the mousepoint and GetValueByPoint which returns the X and Y values of the mousepoint calculated from the ChartPoint. The following code snippet must be given under the Mouse Event handler.

C#

private void chartControl1_ChartRegionMouseUp(object sender, Syncfusion.Windows.Forms.Chart.ChartRegionMouseEventArgs e)

{

Cursor = Cursors.SizeAll;

if (this.isDragging)

{

double newY = Math.Floor(this.chartControl1.ChartArea.GetValueByPoint(e.Point).YValues[0]);

double newX = this.chartControl1.ChartArea.GetValueByPoint(e.Point).X;

if (newY < 0 || newY >= 50 || newX < 0 || newX > 7)

MessageBox.Show("Cannot drag outside chart bounds");

else

{

this.NewYValue(newY);

this.NewXValue(newX);

}

this.isDragging = false;

this.currentRegion = null;

this.selectedDataPoint.Y = 0;

this.selectedDataPoint.X = 0;

this.chartControl1.Redraw(true);

}

this.chartControl1.Series[0].Style.TextFormat = "{0}";

this.chartControl1.Refresh();

}

VB

Private Sub chartControl1_ChartRegionMouseUp(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Chart.ChartRegionMouseEventArgs) Handles ChartControl1.ChartRegionMouseUp

Cursor = Cursors.SizeAll

If Me.isDragging Then

Dim newY As Double = Math.Floor(Me.ChartControl1.ChartArea.GetValueByPoint(e.Point).YValues(0))

Dim newX As Double = Me.ChartControl1.ChartArea.GetValueByPoint(e.Point).X

If newY < 0 OrElse newY >= 50 OrElse newX < 0 OrElse newX > 7 Then

MessageBox.Show("Cannot drag outside chart bounds")

Else

Me.NewYValue(newY)

Me.NewXValue(newX)

End If

Me.selectedDataPoint.Y = 0

Me.selectedDataPoint.X = 0

Me.isDragging = False

Me.currentRegion = Nothing

Me.ChartControl1.Redraw(True)

End If

Me.ChartControl1.Series(0).Style.TextFormat = "{0}"

Me.ChartControl1.Refresh()

End Sub

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied