網站首頁 編程語言 正文
本文實例為大家分享了C#實現chart控件動態曲線繪制的具體代碼,供大家參考,具體內容如下
思想
實驗室要做一個動態曲線繪制,網上方法很多,但是缺乏完整代碼和效果圖的整合,往往總是缺少其一,因此整理如下,方便大家編程,節約時間。
思路:新建一個隊列,利用timer控件,動態的往隊列中加入數據,每次觸發事件,就相當于將隊列中的值全部重新畫一遍。
我的目的是做四個點的動態監測,所以代碼重復了四次,其實應該用4個線程來做,思路就顯得較為清晰了,這也是可以改進的地方。
public partial class 界面_Xtratabcontrol版本_ : Form ? ? { ? ? ? ? private Queue<double> dataQueue1 = new Queue<double>(100); //30個就清空一次 ? ? ? ? private Queue<double> dataQueue2 = new Queue<double>(100); //30個就清空一次 ? ? ? ? private Queue<double> dataQueue3 = new Queue<double>(100); //30個就清空一次 ? ? ? ? private Queue<double> dataQueue4 = new Queue<double>(100); //30個就清空一次 ? ? ? ? private int stress1 = 0;//設置一個壓力值全局變量 ? ? ? ? private int stress2 = 0;//設置一個壓力值全局變量 ? ? ? ? private int stress3 = 0;//設置一個壓力值全局變量 ? ? ? ? private int stress4 = 0;//設置一個壓力值全局變量 ? ? ? ? string monthNow = ""; ? ? ? ? string monthNext = ""; ? ? ? ? string currentTime = ""; ? ? ? ? bool isRefresh = false; ? ? ? ? public 界面_Xtratabcontrol版本_() ? ? ? ? { ? ? ? ? ? ? InitializeComponent(); ? ? ? ? ? ? dataGridView1.AutoGenerateColumns = false; //設置不自動顯示數據庫中未綁定的列 ? ? ? ? ? ? //設置隔行背景色 ? ? ? ? ? ? this.dataGridView1.RowsDefaultCellStyle.BackColor = Color.Bisque; ? ? ? ? ? ? this.dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige; ? ? ? ? } ? ? ? ? private void btnInit_Click(object sender, EventArgs e) ? ? ? ? { ? ? ? ? ? ? InitChart1(); ? ? ? ? ? ? InitChart2(); ? ? ? ? ? ? InitChart3(); ? ? ? ? ? ? InitChart4(); ? ? ? ? } ? ? ? ? private void btnStart_Click(object sender, EventArgs e) ? ? ? ? { ? ? ? ? ? ? this.timer1.Start(); ? ? ? ? } ? ? ? ? private void btnStop_Click(object sender, EventArgs e) ? ? ? ? { ? ? ? ? ? ? this.timer1.Stop(); ? ? ? ? } ? ? ? ? private void timer1_Tick(object sender, EventArgs e) ? ? ? ? { ? ? ? ? ? ? try ? ? ? ? ? ? { ? ? ? ? ? ? ? ? UpdateDate(); //根據當前時間取下一個數據,同時給month賦值 ? ? ? ? ? ? ? ? dataQueue1.Enqueue(stress1); //就是這,不斷往里面加數據。 ? ? ? ? ? ? ? ? dataQueue2.Enqueue(stress2); ? ? ? ? ? ? ? ? dataQueue3.Enqueue(stress3); ? ? ? ? ? ? ? ? dataQueue4.Enqueue(stress4); ? ? ? ? ? ? ? ? if (isRefresh) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? //刷新界面 ? ? ? ? ? ? ? ? ? ? isRefresh = false; ? ? ? ? ? ? ? ? ? ? InitChart1(); ? ? ? ? ? ? ? ? ? ? InitChart2(); ? ? ? ? ? ? ? ? ? ? InitChart3(); ? ? ? ? ? ? ? ? ? ? InitChart4(); ? ? ? ? ? ? ? ? ? ? dataQueue1.Enqueue(stress1); ? ? ? ? ? ? ? ? ? ? dataQueue2.Enqueue(stress2); ? ? ? ? ? ? ? ? ? ? dataQueue3.Enqueue(stress3); ? ? ? ? ? ? ? ? ? ? dataQueue4.Enqueue(stress4); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? this.chart1.Series[0].Points.Clear(); ? ? ? ? ? ? ? ? this.chart2.Series[0].Points.Clear(); ? ? ? ? ? ? ? ? this.chart3.Series[0].Points.Clear(); ? ? ? ? ? ? ? ? this.chart4.Series[0].Points.Clear(); ? ? ? ? ? ? ? ? for (int i = 0; i < dataQueue1.Count; i++) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? this.chart1.Series[0].Points.AddXY((i + 1), dataQueue1.ElementAt(i)); 相當于每次都是重新畫一遍 ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? for (int i = 0; i < dataQueue2.Count; i++) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? this.chart2.Series[0].Points.AddXY((i + 1), dataQueue2.ElementAt(i)); 相當于每次都是重新畫一遍 ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? for (int i = 0; i < dataQueue3.Count; i++) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? this.chart3.Series[0].Points.AddXY((i + 1), dataQueue3.ElementAt(i)); 相當于每次都是重新畫一遍 ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? for (int i = 0; i < dataQueue4.Count; i++) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? this.chart4.Series[0].Points.AddXY((i + 1), dataQueue4.ElementAt(i)); 相當于每次都是重新畫一遍 ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? ? ? catch (Exception ex) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? MessageBox.Show(ex.Message); ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? private void InitChart1() ? ? ? ? { ? ? ? ? ? ? try ? ? ? ? ? ? { ? ? ? ? ? ? ? ? //定義圖表區域 ? ? ? ? ? ? ? ? this.chart1.ChartAreas.Clear(); ? ? ? ? ? ? ? ? ChartArea chartArea1 = new ChartArea("C1"); ? ? ? ? ? ? ? ? this.chart1.ChartAreas.Add(chartArea1); ? ? ? ? ? ? ? ? //this.chart1.Dock = DockStyle.Fill; ? ? ? ? ? ? ? ? //定義存儲和顯示點的容器 ? ? ? ? ? ? ? ? this.chart1.Series.Clear(); ? ? ? ? ? ? ? ? Series series1 = new Series("S1"); ? ? ? ? ? ? ? ? series1.ChartArea = "C1"; ? ? ? ? ? ? ? ? this.chart1.Series.Add(series1); ? ? ? ? ? ? ? ? //設置圖表顯示樣式 ? ? ? ? ? ? ? ? this.chart1.ChartAreas[0].AxisY.Minimum = 30000; ? ? ? ? ? ? ? ? this.chart1.ChartAreas[0].AxisY.Maximum = 50000; ? ? ? ? ? ? ? ? this.chart1.ChartAreas[0].AxisX.Minimum = 1; ? ? ? ? ? ? ? ? this.chart1.ChartAreas[0].AxisX.Maximum = 31; ? ? ? ? ? ? ? ? this.chart1.ChartAreas[0].AxisX.Interval = 1; ? ? ? ? ? ? ? ? this.chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Silver; ? ? ? ? ? ? ? ? this.chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Silver; ? ? ? ? ? ? ? ? //設置標題 ? ? ? ? ? ? ? ? this.chart1.Titles.Clear(); ? ? ? ? ? ? ? ? this.chart1.Titles.Add("S01"); ? ? ? ? ? ? ? ? this.chart1.Titles[0].Text = "1號監測點"; ? ? ? ? ? ? ? ? this.chart1.Titles[0].ForeColor = Color.RoyalBlue; ? ? ? ? ? ? ? ? this.chart1.Titles[0].Font = new System.Drawing.Font("Microsoft Sans Serif", 12F); ? ? ? ? ? ? ? ? //設置圖表顯示樣式 ? ? ? ? ? ? ? ? this.chart1.Series[0].Color = Color.Red; ? ? ? ? ? ? ? ? if (rb1.Checked) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? //this.chart1.Titles[0].Text = string.Format("動態 {0} 顯示", rb1.Text); ? ? ? ? ? ? ? ? ? ? this.chart1.Titles[0].Text = string.Format("1號監測點"); ? ? ? ? ? ? ? ? ? ? this.chart1.Series[0].ChartType = SeriesChartType.Line; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? if (rb2.Checked) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? this.chart1.Titles[0].Text = string.Format("動態 {0} 顯示", rb1.Text); ? ? ? ? ? ? ? ? ? ? this.chart1.Series[0].ChartType = SeriesChartType.Spline; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? this.chart1.Series[0].Points.Clear(); ? ? ? ? ? ? ? ? //DBEngine.ConnectDB("orcl", "dt", "6312"); ? ? ? ? ? ? ? ? dataQueue1.Clear();//清空隊列中所有數據 ? ? ? ? ? ? } ? ? ? ? ? ? catch (Exception ex) ? ? ? ? ? ? { ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? private void InitChart2() ? ? ? ? { ? ? ? ? ? ? try ? ? ? ? ? ? { ? ? ? ? ? ? ? ? //定義圖表區域 ? ? ? ? ? ? ? ? this.chart2.ChartAreas.Clear(); ? ? ? ? ? ? ? ? ChartArea chartArea2 = new ChartArea("C2"); ? ? ? ? ? ? ? ? this.chart2.ChartAreas.Add(chartArea2); ? ? ? ? ? ? ? ? //this.chart1.Dock = DockStyle.Fill; ? ? ? ? ? ? ? ? //定義存儲和顯示點的容器 ? ? ? ? ? ? ? ? this.chart2.Series.Clear(); ? ? ? ? ? ? ? ? Series series2 = new Series("S2"); ? ? ? ? ? ? ? ? series2.ChartArea = "C2"; ? ? ? ? ? ? ? ? this.chart2.Series.Add(series2); ? ? ? ? ? ? ? ? //設置圖表顯示樣式 ? ? ? ? ? ? ? ? this.chart2.ChartAreas[0].AxisY.Minimum = 30000; ? ? ? ? ? ? ? ? this.chart2.ChartAreas[0].AxisY.Maximum = 50000; ? ? ? ? ? ? ? ? this.chart2.ChartAreas[0].AxisX.Minimum = 1; ? ? ? ? ? ? ? ? this.chart2.ChartAreas[0].AxisX.Maximum = 31; ? ? ? ? ? ? ? ? this.chart2.ChartAreas[0].AxisX.Interval = 1; ? ? ? ? ? ? ? ? this.chart2.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Silver; ? ? ? ? ? ? ? ? this.chart2.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Silver; ? ? ? ? ? ? ? ? //設置標題 ? ? ? ? ? ? ? ? this.chart2.Titles.Clear(); ? ? ? ? ? ? ? ? this.chart2.Titles.Add("S02"); ? ? ? ? ? ? ? ? this.chart2.Titles[0].Text = "動態折線圖顯示"; ? ? ? ? ? ? ? ? this.chart2.Titles[0].ForeColor = Color.RoyalBlue; ? ? ? ? ? ? ? ? this.chart2.Titles[0].Font = new System.Drawing.Font("Microsoft Sans Serif", 12F); //標題字體 ? ? ? ? ? ? ? ? //設置圖表顯示樣式 ? ? ? ? ? ? ? ? this.chart2.Series[0].Color = Color.Red; ? ? ? ? ? ? ? ? if (rb1.Checked) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? //this.chart2.Titles[0].Text = string.Format("動態 {0} 顯示", rb1.Text); ? ? ? ? ? ? ? ? ? ? this.chart2.Titles[0].Text = string.Format("2號監測點"); ? ? ? ? ? ? ? ? ? ? this.chart2.Series[0].ChartType = SeriesChartType.Line; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? if (rb2.Checked) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? this.chart2.Titles[0].Text = string.Format("動態 {0} 顯示", rb1.Text); ? ? ? ? ? ? ? ? ? ? this.chart2.Series[0].ChartType = SeriesChartType.Spline; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? this.chart2.Series[0].Points.Clear(); ? ? ? ? ? ? ? ? //DBEngine.ConnectDB("orcl", "dt", "6312"); ? ? ? ? ? ? ? ? dataQueue2.Clear();//清空隊列中所有數據 ? ? ? ? ? ? } ? ? ? ? ? ? catch (Exception ex) ? ? ? ? ? ? { ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? private void InitChart3() ? ? ? ? { ? ? ? ? ? ? try ? ? ? ? ? ? { ? ? ? ? ? ? ? ? //定義圖表區域 ? ? ? ? ? ? ? ? this.chart3.ChartAreas.Clear(); ? ? ? ? ? ? ? ? ChartArea chartArea3 = new ChartArea("C3"); ? ? ? ? ? ? ? ? this.chart3.ChartAreas.Add(chartArea3); ? ? ? ? ? ? ? ? //this.chart1.Dock = DockStyle.Fill; ? ? ? ? ? ? ? ? //定義存儲和顯示點的容器 ? ? ? ? ? ? ? ? this.chart3.Series.Clear(); ? ? ? ? ? ? ? ? Series series3 = new Series("S3"); ? ? ? ? ? ? ? ? series3.ChartArea = "C3"; ? ? ? ? ? ? ? ? this.chart3.Series.Add(series3); ? ? ? ? ? ? ? ? //設置圖表顯示樣式 ? ? ? ? ? ? ? ? this.chart3.ChartAreas[0].AxisY.Minimum = 30000; ? ? ? ? ? ? ? ? this.chart3.ChartAreas[0].AxisY.Maximum = 50000; ? ? ? ? ? ? ? ? this.chart3.ChartAreas[0].AxisX.Minimum = 1; ? ? ? ? ? ? ? ? this.chart3.ChartAreas[0].AxisX.Maximum = 31; ? ? ? ? ? ? ? ? this.chart3.ChartAreas[0].AxisX.Interval = 1; ? ? ? ? ? ? ? ? this.chart3.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Silver; ? ? ? ? ? ? ? ? this.chart3.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Silver; ? ? ? ? ? ? ? ? //設置標題 ? ? ? ? ? ? ? ? this.chart3.Titles.Clear(); ? ? ? ? ? ? ? ? this.chart3.Titles.Add("S03"); ? ? ? ? ? ? ? ? this.chart3.Titles[0].Text = "動態折線圖顯示"; ? ? ? ? ? ? ? ? this.chart3.Titles[0].ForeColor = Color.RoyalBlue; ? ? ? ? ? ? ? ? this.chart3.Titles[0].Font = new System.Drawing.Font("Microsoft Sans Serif", 12F); //標題字體 ? ? ? ? ? ? ? ? //設置圖表顯示樣式 ? ? ? ? ? ? ? ? this.chart3.Series[0].Color = Color.Red; ? ? ? ? ? ? ? ? if (rb1.Checked) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? //this.chart3.Titles[0].Text = string.Format("動態 {0} 顯示", rb1.Text); ? ? ? ? ? ? ? ? ? ? this.chart3.Titles[0].Text = string.Format("3號監測點"); ? ? ? ? ? ? ? ? ? ? this.chart3.Series[0].ChartType = SeriesChartType.Line; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? if (rb2.Checked) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? this.chart3.Titles[0].Text = string.Format("動態 {0} 顯示", rb1.Text); ? ? ? ? ? ? ? ? ? ? this.chart3.Series[0].ChartType = SeriesChartType.Spline; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? this.chart3.Series[0].Points.Clear(); ? ? ? ? ? ? ? ? //DBEngine.ConnectDB("orcl", "dt", "6312"); ? ? ? ? ? ? ? ? dataQueue3.Clear();//清空隊列中所有數據 ? ? ? ? ? ? } ? ? ? ? ? ? catch (Exception ex) ? ? ? ? ? ? { ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? private void InitChart4() ? ? ? ? { ? ? ? ? ? ? try ? ? ? ? ? ? { ? ? ? ? ? ? ? ? //定義圖表區域 ? ? ? ? ? ? ? ? this.chart4.ChartAreas.Clear(); ? ? ? ? ? ? ? ? ChartArea chartArea4 = new ChartArea("C4"); ? ? ? ? ? ? ? ? this.chart4.ChartAreas.Add(chartArea4); ? ? ? ? ? ? ? ? //this.chart1.Dock = DockStyle.Fill; ? ? ? ? ? ? ? ? //定義存儲和顯示點的容器 ? ? ? ? ? ? ? ? this.chart4.Series.Clear(); ? ? ? ? ? ? ? ? Series series4 = new Series("S4"); ? ? ? ? ? ? ? ? series4.ChartArea = "C4"; ? ? ? ? ? ? ? ? this.chart4.Series.Add(series4); ? ? ? ? ? ? ? ? //設置圖表顯示樣式 ? ? ? ? ? ? ? ? this.chart4.ChartAreas[0].AxisY.Minimum = 30000; ? ? ? ? ? ? ? ? this.chart4.ChartAreas[0].AxisY.Maximum = 50000; ? ? ? ? ? ? ? ? this.chart4.ChartAreas[0].AxisX.Minimum = 1; ? ? ? ? ? ? ? ? this.chart4.ChartAreas[0].AxisX.Maximum = 31; ? ? ? ? ? ? ? ? this.chart4.ChartAreas[0].AxisX.Interval = 1; ? ? ? ? ? ? ? ? this.chart4.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Silver; ? ? ? ? ? ? ? ? this.chart4.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Silver; ? ? ? ? ? ? ? ? //設置標題 ? ? ? ? ? ? ? ? this.chart4.Titles.Clear(); ? ? ? ? ? ? ? ? this.chart4.Titles.Add("S04"); ? ? ? ? ? ? ? ? this.chart4.Titles[0].Text = "動態折線圖顯示"; ? ? ? ? ? ? ? ? this.chart4.Titles[0].ForeColor = Color.RoyalBlue; ? ? ? ? ? ? ? ? this.chart4.Titles[0].Font = new System.Drawing.Font("Microsoft Sans Serif", 12F); //標題字體 ? ? ? ? ? ? ? ? //設置圖表顯示樣式 ? ? ? ? ? ? ? ? this.chart4.Series[0].Color = Color.Red; ? ? ? ? ? ? ? ? if (rb1.Checked) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? //this.chart4.Titles[0].Text = string.Format("動態 {0} 顯示", rb1.Text); ? ? ? ? ? ? ? ? ? ? this.chart4.Titles[0].Text = string.Format("4號監測點"); ? ? ? ? ? ? ? ? ? ? this.chart4.Series[0].ChartType = SeriesChartType.Line; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? if (rb2.Checked) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? this.chart4.Titles[0].Text = string.Format("動態 {0} 顯示", rb1.Text); ? ? ? ? ? ? ? ? ? ? this.chart4.Series[0].ChartType = SeriesChartType.Spline; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? this.chart4.Series[0].Points.Clear(); ? ? ? ? ? ? ? ? //DBEngine.ConnectDB("orcl", "dt", "6312"); ? ? ? ? ? ? ? ? dataQueue4.Clear();//清空隊列中所有數據 ? ? ? ? ? ? } ? ? ? ? ? ? catch (Exception ex) ? ? ? ? ? ? { ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? private void UpdateDate() ? ? ? ? { ? ? ? ? ? ? //1 2 3 4號點同時更新 ? ? ? ? ? ? try ? ? ? ? ? ? { ? ? ? ? ? ? ? ? //獲取當前時間的batch值,將batch+1的時間值提取顯示。 ? ? ? ? ? ? ? ? string selectsql = string.Format("select * from stressinfo where operatetime=to_date('{0}','yyyy-mm-dd')", dtp1.Value.ToShortDateString()); ? ? ? ? ? ? ? ? DataTable dtDate = new DataTable(); ? ? ? ? ? ? ? ? dtDate = DBEngine.GetDataTableBySql(selectsql); ? ? ? ? ? ? ? ? if (dtDate.Rows.Count > 0) //4條 ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? string[] getmonthNow = dtp1.Value.ToShortDateString().Split('/'); //有的電腦是'-' ? ? ? ? ? ? ? ? ? ? monthNow = getmonthNow[1]; ? ? ? ? ? ? ? ? ? ? int currentBatch = DBEngine.ObjToInt(dtDate.Rows[0]["batchnum"]); ? ? ? ? ? ? ? ? ? ? //int currentNode = DBEngine.ObjToInt(dtDate.Rows[0]["NODE"]); //當前節點和當前批次確定唯一記錄 ? ? ? ? ? ? ? ? ? ? currentBatch++; ? ? ? ? ? ? ? ? ? ? //獲取下一個顯示的時間值以及應力值 ? ? ? ? ? ? ? ? ? ? string nextsql1 = string.Format("select * from stressinfo where batchnum='{0}' and node=1", currentBatch); ? ? ? ? ? ? ? ? ? ? DataTable dtNext1 = new DataTable(); ? ? ? ? ? ? ? ? ? ? dtNext1 = DBEngine.GetDataTableBySql(nextsql1);//取得了下一個批次的所有應力監測點數據。 ? ? ? ? ? ? ? ? ? ? if (dtNext1.Rows.Count > 0) ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? stress1 = DBEngine.ObjToInt(dtNext1.Rows[0]["CURRENTSTRESS"]); ? ? ? ? ? ? ? ? ? ? ? ? dtp1.Value = DBEngine.ObjToDateTime(dtNext1.Rows[0]["OPERATETIME"]); //日期顯示(之后應該還有各點應力的提取) ? ? ? ? ? ? ? ? ? ? ? ? currentTime = dtp1.Value.ToShortDateString(); ? ? ? ? ? ? ? ? ? ? ? ? string[] datetime = currentTime.Split('/'); ? ? ? ? ? ? ? ? ? ? ? ? monthNext = datetime[1]; ? ? ? ? ? ? ? ? ? ? ? ? if (monthNow != monthNext) ? ? ? ? ? ? ? ? ? ? ? ? ? ? isRefresh = true; ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? else ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? timer1.Stop();//數據到頭了,沒有數據了,batch+1找不到了 ? ? ? ? ? ? ? ? ? ? ? ? btnStop.Focus(); //停止鍵焦點顯示 ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ///第二個點,不用更新數據 ? ? ? ? ? ? ? ? ? ? string nextsql2 = string.Format("select * from stressinfo where batchnum='{0}' and node=2", currentBatch); ? ? ? ? ? ? ? ? ? ? DataTable dtNext2 = new DataTable(); ? ? ? ? ? ? ? ? ? ? dtNext2 = DBEngine.GetDataTableBySql(nextsql2);//取得了下一個批次的所有應力監測點數據。 ? ? ? ? ? ? ? ? ? ? if (dtNext2.Rows.Count > 0) ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? stress2 = DBEngine.ObjToInt(dtNext2.Rows[0]["CURRENTSTRESS"]); ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? else ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? timer1.Stop();//數據到頭了,沒有數據了,batch+1找不到了 ? ? ? ? ? ? ? ? ? ? ? ? btnStop.Focus(); //停止鍵焦點顯示 ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ///第三個點,不用更新數據 ? ? ? ? ? ? ? ? ? ? string nextsql3 = string.Format("select * from stressinfo where batchnum='{0}' and node=3", currentBatch); ? ? ? ? ? ? ? ? ? ? DataTable dtNext3 = new DataTable(); ? ? ? ? ? ? ? ? ? ? dtNext3 = DBEngine.GetDataTableBySql(nextsql3);//取得了下一個批次的所有應力監測點數據。 ? ? ? ? ? ? ? ? ? ? if (dtNext3.Rows.Count > 0) ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? stress3 = DBEngine.ObjToInt(dtNext3.Rows[0]["CURRENTSTRESS"]); ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? else ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? timer1.Stop();//數據到頭了,沒有數據了,batch+1找不到了 ? ? ? ? ? ? ? ? ? ? ? ? btnStop.Focus(); //停止鍵焦點顯示 ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ///第四個點,不用更新數據 ? ? ? ? ? ? ? ? ? ? string nextsql4 = string.Format("select * from stressinfo where batchnum='{0}' and node=4", currentBatch); ? ? ? ? ? ? ? ? ? ? DataTable dtNext4 = new DataTable(); ? ? ? ? ? ? ? ? ? ? dtNext4 = DBEngine.GetDataTableBySql(nextsql4);//取得了下一個批次的所有應力監測點數據。 ? ? ? ? ? ? ? ? ? ? if (dtNext4.Rows.Count > 0) ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? stress4 = DBEngine.ObjToInt(dtNext4.Rows[0]["CURRENTSTRESS"]); ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? else ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? timer1.Stop();//數據到頭了,沒有數據了,batch+1找不到了 ? ? ? ? ? ? ? ? ? ? ? ? btnStop.Focus(); //停止鍵焦點顯示 ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? ? ? catch ? ? ? ? ? ? { ? ? ? ? ? ? } ? ? ? ? } }
因為涉及到一些業務,有些代碼沒有粘,數據是和Oracle數據庫進行交互的,類文件名DBEngine.cs,大家自己做的時候別忘連接數據庫,最終效果圖
這個圖還有優化的控件,我后期要做一下,還是不太好看。
可以實現曲線隨日期動態增加,想到了就不難,我覺得思路挺好的,就記錄一下。
原文鏈接:https://blog.csdn.net/a5pansq/article/details/89365834
相關推薦
- 2022-09-27 在?React?Native?中給第三方庫打補丁的過程解析_React
- 2022-07-16 Linux中啟動Docker容器報錯:Error response from daemon: dri
- 2022-03-08 android?studio項目:綁定服務和線程實現計時器_Android
- 2023-01-17 Pytorch-Geometric中的Message?Passing使用及說明_python
- 2022-09-05 C語言之實現單鏈表指定結點的插入方式_C 語言
- 2022-06-16 python讀取txt數據的操作步驟_python
- 2023-07-05 Spring Boot 啟動報錯 XXX\Tomcat\apache-tomcat-9.0.65\b
- 2022-04-15 基于Redis?zSet實現滑動窗口對短信進行防刷限流的問題_Redis
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支