Profile Picture

Multiple cursors on primaryXAxis

Posted By Tobias Breuer 12 Years Ago
Author
Message
Tobias Breuer
Posted 12 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: Forum Members
Last Active: 9 Years Ago
Posts: 5, Visits: 11

Hi all,

I would like to add multiple cursors on the primary x axis. This by itself is not a problem

but then i like to move these cursors with the mouse individually and this is where I can't seem

to get any further. When using the DataCursorTool, all the cursors get relocated to the mouse position.

Do you have any suggestion how to interact with the single cursors individually?

 

Kind Regards

Tobias



Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Tobias,

You need to dynamically switch the cursor synchronization mode - the problem is that cursors are not hit testable so you need to perform some type of hit testing using logical coordinates. The following example shows how to achieve a chart with two dragable cursors:

   public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        NAxisCursor m_AxisCursor1;
        NAxisCursor m_AxisCursor2;
        NCartesianChart m_Chart;
        bool m_DraggingCursor;

        private void Form1_Load(object sender, EventArgs e)
        {
            m_Chart = (NCartesianChart)nChartControl1.Charts[0];

            NBarSeries bar = new NBarSeries();

            bar.Values.Add(10);
            bar.Values.Add(20);
            bar.Values.Add(30);

            m_Chart.Series.Add(bar);

            NAxis axis = m_Chart.Axis(StandardAxis.PrimaryY);


            m_AxisCursor1 = new NAxisCursor();
            m_AxisCursor1.Value = 15;
            m_AxisCursor1.BeginEndAxis = (int)StandardAxis.PrimaryX;
            m_AxisCursor1.SynchronizeOnMouseAction = MouseAction.None;
            m_AxisCursor1.StrokeStyle.Width = new NLength(3);
            axis.Cursors.Add(m_AxisCursor1);

            m_AxisCursor2 = new NAxisCursor();
            m_AxisCursor2.Value = 25;
            m_AxisCursor2.BeginEndAxis = (int)StandardAxis.PrimaryX;
            m_AxisCursor2.SynchronizeOnMouseAction = MouseAction.None;
            m_AxisCursor2.StrokeStyle.Width = new NLength(3);
            axis.Cursors.Add(m_AxisCursor2);

            NDataCursorTool dataCursorTool = new NDataCursorTool();
            nChartControl1.Controller.Tools.Add(new NSelectorTool());
            nChartControl1.Controller.Tools.Add(dataCursorTool);

            nChartControl1.MouseDown += new MouseEventHandler(nChartControl1_MouseDown);
            nChartControl1.MouseUp += new MouseEventHandler(nChartControl1_MouseUp);
        }

        void nChartControl1_MouseUp(object sender, MouseEventArgs e)
        {
            if (m_DraggingCursor)
            {
                m_AxisCursor1.SynchronizeOnMouseAction = MouseAction.None;
                m_AxisCursor2.SynchronizeOnMouseAction = MouseAction.None;

                m_DraggingCursor = false;
                nChartControl1.Capture = false;
            }
        }

        void nChartControl1_MouseDown(object sender, MouseEventArgs e)
        {
            NPointF viewpoint = new NPointF(e.X, e.Y);

            if (!m_Chart.PlotArea.Contains(viewpoint))
            {
                return;
            }
            NViewToScale1DTransformation tranform = new NViewToScale1DTransformation(nChartControl1.View.Context, m_Chart, (int)StandardAxis.PrimaryY, (int)StandardAxis.PrimaryX);

            double value = 0;
            tranform.Transform(viewpoint, ref value);

            m_AxisCursor1.SynchronizeOnMouseAction = MouseAction.None;
            m_AxisCursor2.SynchronizeOnMouseAction = MouseAction.None;
            m_DraggingCursor = false;

            if (Math.Abs(m_AxisCursor1.Value - value) < 1)
            {
                m_AxisCursor1.SynchronizeOnMouseAction = MouseAction.Move;
                m_DraggingCursor = true;
                nChartControl1.Capture = true;
            }
            if (Math.Abs(m_AxisCursor2.Value - value) < 1)
            {
                m_AxisCursor2.SynchronizeOnMouseAction = MouseAction.Move;
                m_DraggingCursor = true;
                nChartControl1.Capture = true;
            }
        }
    }

The only problem with this code is that you need to provide some hot area around the cursor - in the above code this is achieved trough:

 if (Math.Abs(m_AxisCursor1.Value - value) < 1)

That is problematic if the range of the Y axis is very small (as it will result in a large hot area) so you need to add some code that actually does that in pixels.

Hope this helps - let us know if you meet any problems.



Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic