我正在嘗試將設備的實時心電圖資料輸出顯示到 Winforms 圖表。
它作業得很好,但我似乎無法在添加新點時從圖表左側洗掉資料點,并且主要網格會縮小和增長。
這是計時器中的代碼:
private void butPlayEKG_Click(object sender, EventArgs e) {
chartEKG.Series.Clear();
var series1 = new Series {
Name = "EKG",
Color = Color.LawnGreen,
IsVisibleInLegend = true,
IsXValueIndexed = true,
ChartType = SeriesChartType.Line,
};
this.chartEKG.Series.Add(series1);
playButtonClicked = true;
timer1.Enabled = true;
timer1.Interval = 5;
timer1.Tick = (s, args) => timer1_Tick(series1);
timer1.Start();
}
private void timer1_Tick(Series series1) {
labelClock.Text = DateTime.Now.ToString("HH:mm:ss tt");
string str = String.Empty;
for (int j = 0; j < ekgData.Count; j ) {
str = ekgData[j].EKGWaveform.ToString();
count = str.Split('^');
EKGData = new int[count.Length];
string timeStamp = ekgData[j].VSTimeStamp.ToString();
string format = "yyyyMMddHHmmssfff";
DateTime time = DateTime.ParseExact(timeStamp, format, null);// CultureInfo.InvariantCulture);
adjTime = time;
if (j > 0) {
adjTime = time; time.AddSeconds(1 / 500);
}
for (int i = 0; i < 499; i ) {
EKGData = Array.ConvertAll<string, int>(count, Convert.ToInt32);
series1.Points.AddXY(adjTime.ToString("HH:mm:ss tt"), EKGData[i] * .61);
chartEKG.Update();
}
for (int h = 1; h < j; h ) {
series1.Points.Remove(series1.Points[h]);
chartEKG.Update();
}
}
}
這是圖表代碼:
timer1.Interval = 15;
this.chartEKG.ChartAreas["ChartArea1"].CursorX.LineColor = Color.LawnGreen;
this.chartEKG.ChartAreas["ChartArea1"].CursorY.LineColor = Color.LawnGreen;
this.chartEKG.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = true;
this.chartEKG.ChartAreas["ChartArea1"].AxisY.MajorGrid.Interval = 200;
this.chartEKG.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = true;
this.chartEKG.ChartAreas["ChartArea1"].AxisX.MajorGrid.Interval = 200;
this.chartEKG.ChartAreas["ChartArea1"].AxisY.Title = "mV";
this.chartEKG.ChartAreas["ChartArea1"].AxisX.Minimum = 0;
CultureInfo culture = new CultureInfo("en-US");
ekgData = AnesthVSDatas.CreateEKGWaveformObjects(8237);
可以在此處查看播放視頻:
實時心電資料
uj5u.com熱心網友回復:
注意,time.AddSeconds(1 / 500);沒有效果。我猜您每次都在圖表中同時插入。
也許你的意圖是
time = time.AddSeconds(1d / 500);
還要注意d. 因為1/500等于0。
uj5u.com熱心網友回復:
現在作業。
我意識到我不需要計時器,我需要一個 points.RemoveAt 來從圖表中洗掉點,因為繪制了更多的點。我還通過將所有訊息加入一個長字串而不是單獨決議每條訊息來簡化事情。
這是作業代碼:
private System.Windows.Forms.DataVisualization.Charting.Chart chartEKG;
private System.Windows.Forms.DataVisualization.Charting.Series series1;
private List<AnesthVSData> ekgData;
private static string str;
private string[] count;
chartEKG.Series.Clear();
var series1 = new Series {
Name = "EKG",
Color = Color.LawnGreen,
IsVisibleInLegend = true,
IsXValueIndexed = true,
ChartType = SeriesChartType.Line,
};
this.chartEKG.Series.Add(series1);
playButtonClicked = true;
labelClock.Text = DateTime.Now.ToString("HH:mm:ss tt");
string timeStamp = DateTime.Now.ToString();
for (int j = 0; j < ekgData.Count; j ) {
str = str "^" string.Join("^", ekgData[j].EKGWaveform.ToString());
if (j == 0) {
timeStamp = ekgData[j].VSTimeStamp; //get first VSTimeStamp in series
}
}
str = str.Remove(0, 1); //remove leading ^
count = str.Split('^');
string format = "yyyyMMddHHmmssfff";
DateTime time = DateTime.ParseExact(timeStamp, format, CultureInfo.InvariantCulture);
//adjTime = time;
for (int j = 0; j < count.Length; j ) {
time = time.AddSeconds(0.002); //500 data points per HL7 message, each message is 1s long so 1/500 = 0.002
series1.Points.AddXY(time.ToString("HH:mm:ss"), Convert.ToInt32(count[j]) * 0.61); // 0.61 is resolution correction factor
if (chartEKG.Series[0].Points.Count > 1800) {
chartEKG.Series[0].Points.RemoveAt(0);
chartEKG.ChartAreas[0].AxisX.Minimum = 0; }
chartEKG.Update();
}
這是輸出:
心電圖波形演示
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/332915.html
上一篇:資料結構和演算法
