Lines

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
dataqip
Posts: 14
Joined: Mon Aug 19, 2013 6:43 pm

Lines

Post by dataqip » Tue Aug 27, 2013 12:12 pm

Is it possible to draw lines (horizontal and vertical) on the chart? Or better yet, color fill the gaps between Y-axes and when sweeping.

I want to draw lines to separate the Y-axes (in the gap when stacked) and the data gap on the X-axis when sweeping (this one needs to be updated to move along with the gap).

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: Lines

Post by ArctionPasi » Wed Aug 28, 2013 5:14 pm

Probably best way to make separator lines in Y axis gaps area, is to use Annotations in Arrow style.
Thread-fed multi-channel example with separator lines
Thread-fed multi-channel example with separator lines
SeparatorLines.png (214.27 KiB) Viewed 13881 times
In ExampleThreadMultiChannel.xaml.cs, buttonStartStop_Click

Code: Select all

for (int iChannel = 0; iChannel < m_iChannelCount; iChannel++)
{
AxisY axisY = new AxisY(chartView);
axisY.SetRange(YMin, YMax);
axisY.Title.Font = new WPFFont(System.Drawing.FontFamily.GenericSansSerif, 8.0, System.Drawing.FontStyle.Regular);
axisY.Title.Text = string.Format("Ch {0}", iChannel + 1);
axisY.Title.Angle = 0;
axisY.Units.Visible = false;
chartView.YAxes.Add(axisY);

if (iChannel < m_iChannelCount - 1)
{

//Add a horizontal line to represent a line between axes, in the gap area. 
AnnotationXY annot = new AnnotationXY(chartView, chartView.XAxes[0], axisY);
annot.TargetCoordSystem = AnnotationTargetCoordinates.ScreenCoordinates;
annot.LocationCoordinateSystem = CoordinateSystem.ScreenCoordinates;
annot.Style = AnnotationStyle.Arrow;
annot.ArrowStyleEnd = ArrowStyle.None;
annot.ArrowStyleBegin = ArrowStyle.None;
annot.ArrowLineStyle.Pattern = LinePattern.DashDot;
annot.ArrowLineStyle.Width = 1;
annot.MouseInteraction = false;
annot.ArrowLineStyle.Color = System.Windows.Media.Colors.White;
annot.TextStyle.Visible = false;
chartView.Annotations.Add(annot);
}
}


and in BeforeRendering or SizeChanged event of the chart, run the following code to arrange the annotation lines between in the middle of the gaps:


Code: Select all

            m_chart.BeginUpdate();

            GraphSegmentInfo gsi = m_chart.ViewXY.GetGraphSegmentInfo();
            float fLeft = (float)m_chart.ViewXY.Margins.Left;
            float fRight = (float)(m_chart.ActualWidth - m_chart.ViewXY.Margins.Right); 
            float fSegmentTop = gsi.FirstSegmentTop;


            foreach (AnnotationXY annot in m_chart.ViewXY.Annotations)
            {
                float yCoord = fSegmentTop + gsi.SegmentHeight + gsi.GapHeight / 2f;
                annot.LocationScreenCoords.X = fLeft;
                annot.LocationScreenCoords.Y = yCoord; 
                annot.TargetScreenCoords.X = fRight;
                annot.TargetScreenCoords.Y = yCoord; 
                fSegmentTop += gsi.SegmentShift;
            }
            
            m_chart.EndUpdate(); 
:)



To show a vertical line in the sweeping gap (real-time monitoring position), use a LineSeriesCursor. Update its ValueAtXAxis property to same value than your latest data X value is. Another approach is to use one Annotation in pretty much similar way than instructed above, but you may need to use XAxis.ValueToCoord method to convert the latest X value to location.X and target.X. ;)
LightningChart Support Team, PT

dataqip
Posts: 14
Joined: Mon Aug 19, 2013 6:43 pm

Re: Lines

Post by dataqip » Wed Aug 28, 2013 7:41 pm

I had the same idea with regards to Annotations, but thanks for the code; that helped.

The LineSeriesCursor works well, with one caveat. It's hard to get it close to the gap without disappearing. I tried using an Annotation for this as well, but I'm having trouble calculating the proper screen coordinate (it changes depending on the sweep page).

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: Lines

Post by ArctionPasi » Fri Aug 30, 2013 11:56 am

It seems the annotation gets clipped off if it's placed just in the the edge of sweeping gap. I'd recommend setting xAxis.SweepingGap = 0, and using the following code:

Code: Select all

            //Initialization
            chartView.XAxes[0].SweepingGap = 0; 

            AnnotationXY annotVertLine = new AnnotationXY(chartView, chartView.XAxes[0], chartView.YAxes[0]);
            annotVertLine.TargetCoordSystem = AnnotationTargetCoordinates.ScreenCoordinates;
            annotVertLine.LocationCoordinateSystem = CoordinateSystem.ScreenCoordinates;
            annotVertLine.Style = AnnotationStyle.Arrow;
            annotVertLine.ArrowStyleEnd = ArrowStyle.None;
            annotVertLine.ArrowStyleBegin = ArrowStyle.None;
            annotVertLine.ArrowLineStyle.Pattern = LinePattern.DashDot;
            annotVertLine.ArrowLineStyle.Width = 3;
            annotVertLine.MouseInteraction = false;
            annotVertLine.ArrowLineStyle.Color = System.Windows.Media.Colors.White;
            annotVertLine.TextStyle.Visible = false;
            chartView.Annotations.Add(annotVertLine); 

Code: Select all

            //Updating data 
            ...
            chartView.XAxes[0].ScrollPosition = m_dLatestX;

            //Update vertical sweep gap indicator
            float fXCoord;
            bool bInSecondPage = m_dLatestX >= chartView.XAxes[0].Maximum; 
            if(bInSecondPage)
                fXCoord = chartView.XAxes[0].ValueToCoord(m_dLatestX - (chartView.XAxes[0].Maximum - chartView.XAxes[0].Minimum));
            else 
                fXCoord = chartView.XAxes[0].ValueToCoord(m_dLatestX);


            chartView.Annotations[0].TargetScreenCoords.X =fXCoord;
            chartView.Annotations[0].TargetScreenCoords.Y = (float) chartView.Margins.Top; 

            chartView.Annotations[0].LocationScreenCoords.X = fXCoord;
            chartView.Annotations[0].LocationScreenCoords.Y = (float)(m_chart.ActualHeight - chartView.Margins.Bottom);


Then it produces a running line.
Annotation in sweeping gap
Annotation in sweeping gap
AnnotInSweepingGap.PNG (122.25 KiB) Viewed 13864 times
If you want to make the sweeping yet more stylish, you can use Band with black transparent color in the other edge, as we have made here:
Sweeping gap with band, EEG
Sweeping gap with band, EEG
SweepingGapWithBand.png (441.24 KiB) Viewed 13864 times
http://www.youtube.com/watch?feature=pl ... 1cEr0NAXS4


8-)
LightningChart Support Team, PT

dataqip
Posts: 14
Joined: Mon Aug 19, 2013 6:43 pm

Re: Lines

Post by dataqip » Fri Aug 30, 2013 3:56 pm

Yes, that works much better. Thank you.

Post Reply