We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

 

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

Article ID: Published Date: Last Revised Date: Platform: Control:
60 04/30/2011 07/10/2014 WinForms Chart
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon