Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
225
Drag the Graph line
posted

How do i drag up and down the graph line in the application. I am using ultrawinchart control 7.2

Parents
  • 28496
    Offline posted

    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; }

    public Form1()

    {

    this.UltraChart1 = new UltraChart();

    this.UltraChart1.Dock = DockStyle.Fill;

    this.Controls.Add(this.UltraChart1);

    NumericSeries series1 = new NumericSeries();

    series1.Points.Add(new NumericDataPoint(1.0, "Point A", false));

    series1.Points.Add(new NumericDataPoint(2.0, "Point B", false));

    series1.Points.Add(new NumericDataPoint(3.0, "Point C", false));

    series1.Points.Add(new NumericDataPoint(4.0, "Point D", false));

    this.UltraChart1.Series.Add(series1);

    this.UltraChart1.ChartType = ChartType.LineChart;

    this.UltraChart1.FillSceneGraph += new FillSceneGraphEventHandler(UltraChart1_FillSceneGraph);

    this.UltraChart1.MouseDown += new MouseEventHandler(UltraChart1_MouseDown);

    this.UltraChart1.MouseMove += new MouseEventHandler(UltraChart1_MouseMove);

    this.UltraChart1.MouseLeave += new EventHandler(UltraChart1_MouseLeave);

    this.UltraChart1.MouseUp += new MouseEventHandler(UltraChart1_MouseUp);

    }

    private void UltraChart1_MouseUp(object sender, MouseEventArgs e)

    {

    // clear the draggingprimitive property to terminate the drag operation

    this.DraggingPrimitive = null;

    }

    private void UltraChart1_MouseLeave(object sender, EventArgs e)

    {

    // clear the draggingprimitive property to terminate the drag operation

    this.DraggingPrimitive = null;

    }

    private void UltraChart1_MouseDown(object sender, MouseEventArgs e)

    {

    // save the mousedown location for use in the FillSceneGraph handler.

    this.MouseDownPoint = new Point(e.X, e.Y);

    // invalidate the chart so FillSceneGraph will be raised.

    this.UltraChart1.InvalidateLayers();

    }

    private void UltraChart1_FillSceneGraph(object sender, FillSceneGraphEventArgs e)

    {

    // store the Y axis as a property of this form.

    this.AxisY = e.Grid["Y"] as IAdvanceAxis;

    // loop through the scenegraph.

    foreach (Primitive currentPrimitive in e.SceneGraph)

    {

    Polyline currentPolyline = currentPrimitive as Polyline;if (currentPolyline != null)

    {

    // we found a polyline. examine its points to see if one is hit given the current mouse point.

    foreach (DataPoint currentPoint in currentPolyline.points)

    {

    if (currentPoint.HitTest(this.MouseDownPoint))

    {

    // we found a point which matches our mouse point. store it as DraggingPrimitive.

    this.DraggingPrimitive = currentPoint;

    }

    }

    }

    }

    }

    private void UltraChart1_MouseMove(object sender, MouseEventArgs e)

    {

    // if DraggingPrimitive is not null, a drag is in progress.

    if (this.DraggingPrimitive != null)

    {

    // get the datapoint off the primitive

    NumericDataPoint dataPoint = this.DraggingPrimitive.DataPoint as NumericDataPoint;if (dataPoint != null && this.AxisY != null)

    {

    // change the datapoint value and invalidate the chart.

    dataPoint.Value = (double)this.AxisY.MapInverse(e.Y);this.UltraChart1.InvalidateLayers();

    }

    }

    }

    }

Reply Children