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
80
Changing extent of axis using mouse interaction
posted

hi,

I want to change the extent of the axis by using the mouse dragging  as you do in dragging data point.

Parents
No Data
Reply
  • 17605
    posted

    You can try the following code: 

    public class MovingAxisTool : InteractionTool

    {

    private const int size = 2;

    private Point prevPoint;

    /// <summary>

    /// Initializes a new instance of the <see cref="MovingAxisTool"/> class.

    /// </summary>

    /// <param name="ultraChart">The ultra chart.</param>

    public MovingAxisTool(UltraChart ultraChart): base(ultraChart)

    {

    }

    /// <summary>

    /// Determines whether this tool can start.

    /// </summary>

    /// <returns>

    /// <c>true</c> if this tool can start; otherwise, <c>false</c>.

    /// </returns>

    public override bool CanStart()

    {

    ChartLayer chartLayer = this.ChartCore.GetChartLayer();

    IAdvanceAxis axisY = chartLayer.Grid["Y"] as IAdvanceAxis;

    this.prevPoint = this.LastInput.ViewPoint;

    double yValue = (double)axisY.MapInverse(this.prevPoint.Y);

    if (Math.Abs(yValue - (double)axisY.Minimum) < size)

    {

    return true;

    }

    return false;

    }

    public override void Start()

    {

    base.Start();System.Windows.Forms.Cursor.Current = Cursors.SizeNS;

    }

     

    /// <summary>

    /// Called when this tool is started and the mouse is moved.

    /// </summary>

    public override void MouseMove()

    {

    base.MouseMove();

     

    int dy = this.LastInput.ViewPoint.Y - prevPoint.Y;

    int newExtend = this.UltraChart.Axis.X.Extent - dy;

    if (newExtend < 0)

    {

    newExtend = 0;

    }

    if (newExtend > 500)

    {

    newExtend = 500;

    }

    this.UltraChart.Axis.X.Extent = newExtend;

    this.prevPoint = this.LastInput.ViewPoint;

    this.InvalidateView(CacheLevel.ImageLevelCache);

    }

     

    /// <summary>

    /// Called when this tool stops.

    /// </summary>

    public override void Stop()

    {

    System.Windows.Forms.
    Cursor.Current = Cursors.Default;base.Stop();

    }

    ...

    private void Form1_Load(object sender, EventArgs e)

    {

    this.ultraChart1.DataSource = DemoTable.Table();

    this.ultraChart1.DataBind();

    MovingAxisTool movingAxisTool = new MovingAxisTool(this.ultraChart1);

    this.ultraChart1.AddMouseDownTool(movingAxisTool);

    }

     

Children