private void Chart1_AnnotationPositionChanging(object sender, System.Windows.Forms.DataVisualization.Charting.AnnotationPositionChangingEventArgs e) { if (SnapToDataPoint.Checked) { // get the annotation object from the AnnotationPositionChangingEventArgs Annotation annotation = e.Annotation; if (!float.IsNaN(e.NewAnchorLocation.X)) { // get the nearest point to the new location PointF point = FindNearestDataPoint(e.NewAnchorLocation.X, e.NewAnchorLocation.Y); annotation.AnchorDataPoint = Chart1.Series[0].Points[(int)point.X - 1]; e.NewAnchorLocationX = point.X; e.NewAnchorLocationY = point.Y; } } else { if (!float.IsNaN(e.NewAnchorLocation.X) && e.NewAnchorLocation.X > Chart1.ChartAreas[0].AxisX.Maximum) { e.NewAnchorLocationX = (float)(Chart1.ChartAreas[0].AxisX.Maximum); } else if (!float.IsNaN(e.NewAnchorLocation.X) && e.NewAnchorLocation.X < Chart1.ChartAreas[0].AxisX.Minimum) { e.NewAnchorLocationX = 0; } if (!float.IsNaN(e.NewAnchorLocation.X) && e.NewAnchorLocation.Y > Chart1.ChartAreas[0].AxisY.Maximum) { e.NewAnchorLocationY = (float)(Chart1.ChartAreas[0].AxisY.Maximum); } else if (!float.IsNaN(e.NewAnchorLocation.Y) && e.NewAnchorLocation.Y < 1) { e.NewAnchorLocationY = 1; } } }
private void chart_AnnotationPositionChanging(object sender, AnnotationPositionChangingEventArgs e) { int classIndex = (int)e.Annotation.Tag; double[] thresholds = Content.Model.Thresholds.ToArray(); thresholds[classIndex] = e.NewLocationY; Array.Sort(thresholds); Content.Model.SetThresholdsAndClassValues(thresholds, Content.Model.ClassValues); }
private void chart_AnnotationPositionChanging(object sender, AnnotationPositionChangingEventArgs e) { var step = (trainingMax - trainingMin) / drawingSteps; double newLocation = step * (long)Math.Round(e.NewLocationX / step); var axisX = chart.ChartAreas[0].AxisX; if (newLocation >= axisX.Maximum) newLocation = axisX.Maximum - step; if (newLocation <= axisX.Minimum) newLocation = axisX.Minimum + step; e.NewLocationX = newLocation; UpdateCursor(); }