Drag a line segment in ViewXY

A forum dedicated to WinForms version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
lokesh
Posts: 45
Joined: Tue Feb 14, 2017 8:48 am

Drag a line segment in ViewXY

Post by lokesh » Mon Mar 06, 2017 9:18 pm

Hi,
I was wondering if I could drag a line segment of the LineCollection in the ViewXY.

I have a small pictorial illustration below:
lineDrag.PNG
lineDrag.PNG (6.29 KiB) Viewed 8620 times
I tried to do that using LineCollection, but I couldn't find a MouseMove event to handle this. Now, I could do this by using MouseDown and MouseUp, but I need it to be more interactive. Is there a way to accomplish this (other than running a timer)?

Please excuse by arrow drawing skills.

Thanks.

Regards,
Lokesh

lokesh
Posts: 45
Joined: Tue Feb 14, 2017 8:48 am

Re: Drag a line segment in ViewXY

Post by lokesh » Tue Mar 07, 2017 2:52 pm

Hi,
I finally found a way to do this using PointLineSeries and SeriesEventMarker by placing a SeriesEventMarker at the centre of 2 points.
But, when I update a point in the Points array of PointLineSeries like this

Code: Select all

chart.ViewXY.PointLineSeries[0].Points[mrkrIndx] = new SeriesPoint(chart.ViewXY.PointLineSeries[0].Points[mrkrIndx].X, yVal);
it is taking some time to get updated on the chart. I am calling begin and end updates before and after respectively.

Thanks.

Regards,
Lokesh

ArctionKestutis
Posts: 552
Joined: Mon Mar 14, 2016 9:22 am

Re: Drag a line segment in ViewXY

Post by ArctionKestutis » Wed Mar 08, 2017 2:29 pm

Hi Lokesh,

You may try to use chart's mouse events. See forum answer for Bands drawing: viewtopic.php?f=16&t=1003&p=3612#p3612
_chart.ViewXY.LineCollections.IsMouseOver method should inform you whenever you above desired object.

All the best,
Kestutis

lokesh
Posts: 45
Joined: Tue Feb 14, 2017 8:48 am

Re: Drag a line segment in ViewXY

Post by lokesh » Wed Mar 08, 2017 3:30 pm

Hi Dr.,
Thanks for the reply and suggestion.
But, I am planning to proceed with the PointLineSeries and SeriesEventMarkers as I mentioned in my last post. I am having better control over the lines now.
The problem I face with this is that I have to clone and copy the PointLineSeries.Points back to itself for the update to be spontaneous. Instead, if I do the follow,

Code: Select all

chart.ViewXY.PointLineSeries[0].Points[mrkrIndx] = new SeriesPoint(chart.ViewXY.PointLineSeries[0].Points[mrkrIndx].X, yVal);
it is taking some time to reflect the change on the chart even after using begin and end update. Not that this is a big issue, but I have to copy the whole array back even though all I want to modify is 2 points.

Thanks.

Regards,
Lokesh

ArctionKestutis
Posts: 552
Joined: Mon Mar 14, 2016 9:22 am

Re: Drag a line segment in ViewXY

Post by ArctionKestutis » Fri Mar 10, 2017 9:15 am

Hi Lokesh,

If your PointSeries (including LineCollection) is not updated you are missing InvalidateData() method.
Probably you already achieved that you wanted, but you may take a look at this implementation as well. For dragging lines I used LineSeriesCursor (horizontal drag) and ConstantLine (vertical drag). Both are made transparent color, as they extend through all vertical or horizontal view respectively. Another good thing about them is mouse icon changes automatically to VSplit or HSplit (which you have been asking in another post). Both of Lines have PositionChanged / ValueChanged event there you could update any object coordinates. In this example I was updating LineCollection's line values. However, it could be Points, Annotation, SeriesEVentMarkers etc.

Code: Select all

using System.Drawing;
using System.Windows.Forms;

using Arction.WinForms.Charting;
using Arction.WinForms.Charting.Axes;
using Arction.WinForms.Charting.SeriesXY;
using Arction.WinForms.Charting.Views.ViewXY;
using Arction.WinForms.Charting.Annotations;

namespace DragSegment
{
    public partial class Form1 : Form
    {
        private LightningChartUltimate _chart = null;

        public Form1()
        {
            InitializeComponent();

            CreateChart();
        }

        /// <summary>
        /// Create chart.
        /// </summary>
        private void CreateChart()
        {
            _chart = new LightningChartUltimate();

            // Disable rendering, strongly recommended before updating chart properties.
            _chart.BeginUpdate();

            _chart.Parent = this;
            _chart.Dock = DockStyle.Fill;

            // Hide legend box.
            _chart.ViewXY.LegendBox.Visible = false;

            // Setup x-axis.
            AxisX axisX = _chart.ViewXY.XAxes[0];
            axisX.SetRange(0, 20);
            axisX.ScrollMode = XAxisScrollMode.None;
            axisX.ValueType = AxisValueType.Number;

            // Setup y-axis.
            _chart.ViewXY.YAxes[0].SetRange(0, 100);

            //Add a line series cursor 
            LineSeriesCursor cursor = new LineSeriesCursor(_chart.ViewXY, axisX);
            cursor.ValueAtXAxis = 8;    
            cursor.SnapToPoints = false;
            cursor.LineStyle.Color = Color.Transparent;
            cursor.PositionChanged += Cursor_PositionChanged;
            _chart.ViewXY.LineSeriesCursors.Add(cursor);

            //Add a ConstantLine (horizontal) 
            ConstantLine splitter = new ConstantLine(_chart.ViewXY, axisX, _chart.ViewXY.YAxes[0]);
            splitter.LineStyle.Color = Color.Transparent;
            splitter.ShowInLegendBox = false;
            splitter.MouseHighlight = MouseOverHighlight.None;
            splitter.LineStyle.Width = 5;
            splitter.Value = 75;
            splitter.ValueChanged += Splitter_ValueChanged;
            _chart.ViewXY.ConstantLines.Add(splitter);

            LineCollection lineCollection = new LineCollection(_chart.ViewXY, _chart.ViewXY.XAxes[0], _chart.ViewXY.YAxes[0]);
            lineCollection.LineStyle.Color = Color.Yellow;
            lineCollection.LineStyle.Width = 5;
            lineCollection.LineStyle.AntiAliasing = LineAntialias.None;
            lineCollection.Lines = new SegmentLine[]
            {
                new SegmentLine(8.0, 75, 12.0, 75), // horizontal line
                new SegmentLine(8.0, 25, 8.0, 75),  // vertical line
            };
            _chart.ViewXY.LineCollections.Add(lineCollection);

            // Allow chart rendering.
            _chart.EndUpdate();
        }

        int _iImageCount = 0;

        private void Splitter_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            _chart.BeginUpdate();

            double dNewValue = _chart.ViewXY.ConstantLines[0].Value;

            _chart.ViewXY.LineCollections[0].Lines[0].AY = _chart.ViewXY.LineCollections[0].Lines[0].BY = dNewValue;
            _chart.ViewXY.LineCollections[0].Lines[1].BY = dNewValue;
            _chart.ViewXY.LineCollections[0].InvalidateData();

            _chart.EndUpdate();
        }

        private void Cursor_PositionChanged(object sender, PositionChangedEventArgs e)
        {
            _chart.BeginUpdate();

            double dNewValue = _chart.ViewXY.LineSeriesCursors[0].ValueAtXAxis;

            _chart.ViewXY.LineCollections[0].Lines[0].AX = dNewValue;
            _chart.ViewXY.LineCollections[0].Lines[1].AX = _chart.ViewXY.LineCollections[0].Lines[1].BX = dNewValue;
            _chart.ViewXY.LineCollections[0].InvalidateData();

            _chart.EndUpdate();
        }
    }
}
All the best,
Kestutis

lokesh
Posts: 45
Joined: Tue Feb 14, 2017 8:48 am

Re: Drag a line segment in ViewXY

Post by lokesh » Fri Mar 10, 2017 3:59 pm

Hi Dr.,
Thanks a lot. That was what I was looking for.

Regards,
Lokesh

Post Reply