How do i drag up and down the graph line in the application. I am using ultrawinchart control 7.2
the following code demonstrates one technique for mouse dragging the datapoints in a line chart.
for simplicity, it uses the FillSceneGraph event which was added in 7.3. so if you want to use this in 7.2 or earlier, you'll have to implement ILayer as described in these topics: http://help.infragistics.com/Help/NetAdvantage/NET/2007.2/CLR2.0/html/Chart_Layers.html
using System;
using Infragistics.Win.UltraWinChart;
using System.Windows.Forms;
using System.Data;
using Infragistics.UltraChart.Resources.Appearance;
using Infragistics.UltraChart.Core.Primitives;
using Infragistics.UltraChart.Shared.Events;
using Infragistics.UltraChart.Shared.Styles;
using Infragistics.UltraChart.Core.Layers;
using Infragistics.UltraChart.Core;
using System.Drawing;
public partial class Form1 : Form
{
private UltraChart UltraChart1 { get; set; }
private IAdvanceAxis AxisY { get; set; }
private Primitive DraggingPrimitive { get; set; }
private Point MouseDownPoint { get; set; }
this.UltraChart1.Dock = DockStyle.Fill;
NumericSeries series1 = new NumericSeries();
series1.Points.Add(new NumericDataPoint(2.0, "Point B", false));
series1.Points.Add(new NumericDataPoint(4.0, "Point D", false));
this.UltraChart1.ChartType = ChartType.LineChart;
this.UltraChart1.MouseDown += new MouseEventHandler(UltraChart1_MouseDown);
this.UltraChart1.MouseLeave += new EventHandler(UltraChart1_MouseLeave);
}
// clear the draggingprimitive property to terminate the drag operation
// save the mousedown location for use in the FillSceneGraph handler.
// invalidate the chart so FillSceneGraph will be raised.
// store the Y axis as a property of this form.
// loop through the scenegraph.
// we found a polyline. examine its points to see if one is hit given the current mouse point.
// we found a point which matches our mouse point. store it as DraggingPrimitive.
// if DraggingPrimitive is not null, a drag is in progress.
// get the datapoint off the primitive
// change the datapoint value and invalidate the chart.
Hi David Negley , thanks for your great help. It works fine. I have one more question. Once User drag and leave the graph line. How to i get the new dragged Line points (x.y).
try adding an AxisX property and set it to Grid["X"], following the code used for AxisY. then you can use its MapInverse function just like you did with AxisY.
in the FillSceneGraph event handler, we loop through the primitives seeking Polylines, then loop through the DataPoints in each Polyline, hit testing each one. if that search comes up null, we are not over a data point.
you could still be over a line segment in this case, but we're only making the datapoints interactive, not the segments in between. determining if you're on a line segment in between points will be a bit trickier.