using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace CPFTrack { public partial class FormStripChart : Form { private Form1 form1; public FormStripChart(Form1 f1) { InitializeComponent(); // form1 = new Form1(); form1 = f1; form1.OnIUSBLUpdate += new Form1.IUSBLUpdateHandler(updateIUSBL); } private void updateIUSBL(object sender, Form1.IUSBLData e) { updateStripChart(e); } private static TimeSpan xSpan = new TimeSpan(0, 2, 0); private static DateTime xMin; private static double startDepth = 0.0; private static double depthRange = 10.0; private void updateStripChart(Form1.IUSBLData iusblData) { xMin = iusblData.timeStamp - xSpan; if (!autoScaleY) { chartStripChart.ChartAreas[0].AxisX.Maximum = iusblData.timeStamp.ToOADate(); chartStripChart.ChartAreas["ChartArea1"].AxisX.Minimum = xMin.ToOADate(); chartStripChart.ChartAreas[0].AxisY.Maximum = startDepth; chartStripChart.ChartAreas["ChartArea1"].AxisY.Minimum = startDepth - depthRange; } else { //chartStripChart.ChartAreas[0].AxisX.IntervalAutoMode = true; } if (running) { //if (chartStripChart.Series["Series1"].Points.Count >= 10) // chartStripChart.Series["Series1"].Points.Remove(0); chartStripChart.Series["Series1"].Points.AddXY(iusblData.timeStamp.ToOADate(), iusblData.zValue); Console.WriteLine("Points count = " + chartStripChart.Series["Series1"].Points.Count.ToString()); tbDepth.Text = iusblData.zValue.ToString("f1"); } } private void vsbStartDepth_Scroll(object sender, ScrollEventArgs e) { startDepth = vsbStartDepth.Value; } private void vsbDepthRange_Scroll(object sender, ScrollEventArgs e) { depthRange = vsbDepthRange.Value; } private static bool autoScaleY = true; private void autoScaleYToolStripMenuItem_Click(object sender, EventArgs e) { autoScaleY = !autoScaleY; if( autoScaleY ) { chartStripChart.ChartAreas[0].AxisY.Minimum = double.NaN; chartStripChart.ChartAreas[0].AxisY.Maximum = double.NaN; } } private static bool running = false; private void startToolStripMenuItem_Click(object sender, EventArgs e) { running = !running; } private void FormStripChart_FormClosing(object sender, FormClosingEventArgs e) { running = false; } } }