How to find y values.

A forum dedicated to WinForms version of LightningChart Ultimate.

Moderator: Arction_LasseP

ehdrnsep
Posts: 48
Joined: Mon Jan 12, 2015 6:52 am

How to find y values.

Post by ehdrnsep » Fri Jan 23, 2015 8:30 am

Hello.

Sorry, I do not speak English well. :oops:
Our company is located in the test before you buy LightningChart.

1. How to find y values? I have been using SampleDataSeries. Please refer to the find.zip file.

Code: Select all

 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.cbType.SelectedIndex = 0;

            CreateSampleData();
        }

        private void CreateSampleData()
        {
            ViewXY chartView = this.lightningChartUltimate1.ViewXY;

            var series = this.lightningChartUltimate1.ViewXY.SampleDataSeries[0];
            series.LineStyle.Color = Color.Blue;
            series.SampleFormat = Arction.LightningChartUltimate.SampleFormat.SingleFloat;
            series.SamplingFrequency = 10;
            series.FirstSampleTimeStamp = 0;

            int iPointCount = 501;
            float[] aPoints = new float[iPointCount];
            double dX = 0;
            const double dXInterval = 0.1;
            series.SamplingFrequency = 100;
            series.FirstSampleTimeStamp = 0;
            for (int iPoint = 0; iPoint < iPointCount; iPoint++)
            {
                dX = (double)iPoint * dXInterval;
                aPoints[iPoint] = (int)(50.0 + 30.0 * Math.Sin(dX / 5.0) + 1.0 * Math.Sin(dX * 5.0) + 15.0 * Math.Cos(dX));
            }

            chartView.XAxes[0].SetRange(0, iPointCount / series.SamplingFrequency);
            chartView.YAxes[0].SetRange(0, 100);
            series.AddSamples(aPoints, true);
        }

        private void btnFind_Click(object sender, EventArgs e)
        {
            float value = Convert.ToSingle(tbValue.Text);
            if (this.cbType.SelectedIndex == 0)
            {
                //Find X value
                FInd(value, 0);
            }
            else
            {
                //Find Y value
                FInd(float.NaN, value);
            }
            lightningChartUltimate1.Invalidate();
        }

        void FInd(float x , float y)
        {
            var series = this.lightningChartUltimate1.ViewXY.SampleDataSeries[0];
            
            series.SeriesEventMarkers.Clear();

            //Add event marker to the series
            SeriesEventMarker marker = new SeriesEventMarker(series);
            marker.Label.Visible = false;
            marker.Symbol.Shape = Shape.Cross;
            marker.Symbol.Angle = 45;
            marker.Symbol.Width = 20;
            marker.Symbol.Height = 20;
            marker.Symbol.Color1 = Color.White;

            marker.XValue = x;
            marker.YValue = y;
            
            marker.HorizontalPosition = SeriesEventMarkerHorizontalPosition.SnapToPoints;
            marker.VerticalPosition = SeriesEventMarkerVerticalPosition.TrackSeries;


            series.SeriesEventMarkers.Add(marker);
        }
    }
2. It supports cross cursor, such as third image?

Thank you.
Attachments
Cross cursor
Cross cursor
3.png (12.88 KiB) Viewed 3858 times
I want to look like a red cross.
I want to look like a red cross.
2.png (94.77 KiB) Viewed 3861 times
1.png
1.png (98.97 KiB) Viewed 3861 times

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

Re: How to find y values.

Post by ArctionPasi » Fri Jan 23, 2015 9:43 am

Hi,

it seems find.zip is missing.

1.
You can simply use sampleDataSeries.SolveNearestSampleByValue method. That solves nearest data point to given X axis value (such as a marker or LineSeriesCursor's position).

Alternatively, you can use sampleDataSeries.SolveNearestSampleByCoord to find nearest data point given screen coordinate (such as chart.MouseMove event handler's e.X, e.Y).


2. Yes you can use custom bitmaps for markers.
Marker with bitmap symbol
Marker with bitmap symbol
Marker with bitmap.jpg (88.85 KiB) Viewed 3855 times
Set the Bitmap image in the marker.Symbol.BitmapImage property and set marker.Symbol.Shape = Bitmap.
LightningChart Support Team, PT