using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using NationalInstruments; using NationalInstruments.UI.WindowsForms; using NationalInstruments.UI; using Nevron.Chart; using Nevron.GraphicsCore; using Nevron; using Nevron.Dom; namespace ChartingTestBed { public partial class StripChartTestFW : Form { NLineSeries series; NChart chart; TimeSpan chartRange; DateTime lastMeasurementTime = DateTime.MinValue; NDateTimeScaleConfigurator scaleConf; int counter = 0; public StripChartTestFW() { InitializeComponent(); /******************** * NI * ********************/ stripChart.XAxes[0].Mode = NationalInstruments.UI.AxisMode.StripChart; stripChart.XAxes[0].Range = new NationalInstruments.UI.Range(DateTime.Now, TimeSpan.FromSeconds(5.0)); stripChart.YAxes[0].Mode = NationalInstruments.UI.AxisMode.Fixed; stripChart.YAxes[0].Range = new NationalInstruments.UI.Range(-1.0, 1.0); stripChart.Plots[0].DefaultStart = DataConverter.Convert(DateTime.MinValue); stripChart.XAxes[0].MajorDivisions.LabelFormat = new NationalInstruments.UI.FormatString(NationalInstruments.UI.FormatStringMode.DateTime, "mm:ss:ff \\min"); stripChart.Plots[0].AntiAliased = true; stripChart.Plots[0].LineWidth = 2; /********************** * NEVRON * **********************/ chartRange = TimeSpan.FromSeconds(5); // setup chart chart = nevronChartCtrl.Charts[0]; chart.Projection.SetPredefinedProjection(PredefinedProjection.Orthogonal); chart.BoundsMode = BoundsMode.Stretch; chart.Location = new NPointL(new NLength(5, NRelativeUnit.ParentPercentage), new NLength(5, NRelativeUnit.ParentPercentage)); chart.Size = new NSizeL(new NLength(90, NRelativeUnit.ParentPercentage), new NLength(90, NRelativeUnit.ParentPercentage)); chart.Wall(ChartWallType.Left).Width = 0.0f; chart.BackgroundFillStyle = new NColorFillStyle(Color.White); // setup scale scaleConf = new NDateTimeScaleConfigurator(); // disable tick rounding scaleConf.RoundToTickMax = false; scaleConf.RoundToTickMin = false; // change formatting to minute:second scaleConf.LabelValueFormatter = new NDateTimeValueFormatter("mm:ss"); chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleConf; // setup axis chart.Axis(StandardAxis.PrimaryY).View = new NRangeAxisView(new NRange1DD(-1, 1)); chart.Axis(StandardAxis.PrimaryX).View = new NRangeAxisView(new NRange1DD(DateTime.MinValue.ToOADate(),(DateTime.MinValue + chartRange).ToOADate()) ); chart.Axis(StandardAxis.Depth).Visible = false; //scaleConf.CustomLabels.Add(DateTime.MinValue.ToString()); //scaleConf.CustomLabels.Add(DateTime.MinValue + chartRange).ToString(); //maxRange.Text = DateTime.FromOA+ // Date( chart.Axis(StandardAxis.PrimaryX).ViewRange.End ).ToString("mm:ss:ffff"); //minRange.Text = DateTime.FromOADate(chart.Axis(StandardAxis.PrimaryX).ViewRange.Begin).ToString("mm:ss:ffff"); // add series series = (NLineSeries)chart.Series.Add(SeriesType.Line); series.UseXValues = true; series.Name = "Sinus"; series.MultiLineMode = MultiLineMode.Series; series.DataLabelStyle.Visible = false; series.Values.ValueFormatter = new NNumericValueFormatter("0.0"); series.BorderStyle.Color = Color.Green; series.BorderStyle.Width = new NLength(2, NGraphicsUnit.Pixel); series.FillStyle = new NColorFillStyle(Color.Green); //// Create the UI strip chart control //IStripChart chart = new NIStripChart(); //// Specifiy axis properties (scale, style, behaviour) //IxAxis x = new NIxAxis(); //IyAxis y = new NIyAxis(); //// Create the plot which represents one channel //IPlot plot = chart.createPlot(x, y); //// Create an object which produces "fake" measurement data //DataGenerator dg = new DataGenerator(); //// Tell the DataGenerator to which plots it should send its data //dg.notify(plot); } private void dataFeedTimer_Tick(object sender, EventArgs e) { /******************** * NI * ********************/ // Use sinus as fake data generator double sinus = Math.Sin( ( (float)DateTime.Now.Millisecond / 1000.0 ) * 2.0 * Math.PI ); // Append current sinus value to the first plot of this graph // and increment the time value by 100ms this.stripChart.PlotYAppend(sinus, TimeSpan.FromMilliseconds(dataFeedTimer.Interval)); /********************** * NEVRON * **********************/ series.Values.Add(sinus); DateTime newMeasureTime = lastMeasurementTime + TimeSpan.FromMilliseconds(dataFeedTimer.Interval); series.XValues.Add( newMeasureTime ); if(!chart.Axis(StandardAxis.PrimaryX).ViewRange.Contains(newMeasureTime.ToOADate())) { chart.Axis(StandardAxis.PrimaryX).View = new NRangeAxisView(new NRange1DD( (newMeasureTime - chartRange).ToOADate(),newMeasureTime.ToOADate() ) ); // update range labels //maxRange.Text = DateTime.FromOADate(chart.Axis(StandardAxis.PrimaryX).ViewRange.End).ToString("mm:ss:ffff"); //minRange.Text = DateTime.FromOADate(chart.Axis(StandardAxis.PrimaryX).ViewRange.Begin).ToString("mm:ss:ffff"); //scaleConf.CustomLabels.Clear(); //scaleConf.CustomLabels.Add(DateTime.FromOADate(chart.Axis(StandardAxis.PrimaryX).ViewRange.End).ToString()); //scaleConf.CustomLabels.Add(DateTime.FromOADate(chart.Axis(StandardAxis.PrimaryX).ViewRange.Begin).ToString()); series.XValues.RemoveAt(0); series.Values.RemoveAt(0); } lastMeasurementTime = newMeasureTime; nevronChartCtrl.Refresh(); } private void startBtn_Click(object sender, EventArgs e) { /******************** * NI * ********************/ stripChart.Cursors.Clear(); this.dataFeedTimer.Start(); } private void stopBtn_Click(object sender, EventArgs e) { this.dataFeedTimer.Stop(); /******************** * NI * ********************/ XYCursor vertCurs = new NationalInstruments.UI.XYCursor(); vertCurs.XPosition = stripChart.XAxes[0].Range.Minimum + stripChart.XAxes[0].Range.Interval / 2.0; vertCurs.VerticalCrosshairMode = NationalInstruments.UI.CursorCrosshairMode.FullLength; vertCurs.LabelVisible = true; stripChart.Cursors.Add(vertCurs); } private void updateRateCtrl_ValueChanged(object sender, EventArgs e) { dataFeedTimer.Interval = (int)updateRateCtrl.Value; } } }