C# Chart繪制簡單圖形波形
更新時間:2022年02月17日 09:26:18 作者:鶴影隨行
這篇文章主要為大家詳細(xì)介紹了C# Chart繪制簡單圖形波形,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了C# Chart繪制簡單圖形波形的具體代碼,供大家參考,具體內(nèi)容如下
此次用C#繪制波形使用的是Chart控件
1、將Chart控件拖進主界面,然后設(shè)置屬性。

//? // chart1 //? chartArea2.Name = "ChartArea1"; this.chart1.ChartAreas.Add(chartArea2); legend2.Name = "Legend1"; this.chart1.Legends.Add(legend2); this.chart1.Location = new System.Drawing.Point(36, 6); this.chart1.Name = "chart1"; series3.BorderWidth = 3; series3.ChartArea = "ChartArea1"; series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; series3.Legend = "Legend1"; series3.Name = "系列1"; series4.BorderWidth = 2; series4.ChartArea = "ChartArea1"; series4.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; series4.Legend = "Legend1"; series4.Name = "系列2"; this.chart1.Series.Add(series3); this.chart1.Series.Add(series4); this.chart1.Size = new System.Drawing.Size(839, 499); this.chart1.TabIndex = 0; this.chart1.Text = "chart1";
2、畫線委托函數(shù)
public delegate void ChartDelegate(int series, double Value_Y_Axis); // 聲明委托
public void DrawPoint(int series, double Value_Y_Axis)
{
?? ?try
?? ?{
?? ??? ?if (this.chart1.InvokeRequired)
?? ??? ?{
?? ??? ??? ?this.chart1.Invoke((ChartDelegate)DrawPoint, series, Value_Y_Axis);
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?this.chart1.Series[series - 1].Points.Add(Value_Y_Axis);
?? ??? ?}
?? ?}
?? ?catch
?? ?{
?? ??? ?MessageBox.Show("ERROR!");
?? ?}
?? ?//chart1.Series[series - 1].Points.Add(Value_Y_Axis);
}3、設(shè)置一個按鍵,然后設(shè)置按鍵點擊觸發(fā)時候的定時器Timer屬性,用來觸發(fā)波形產(chǎn)生(用控件按鍵觸發(fā))
private void button3_Click(object sender, EventArgs e)
{
?? ?System.Timers.Timer timer11 = new System.Timers.Timer(400); // 每400ms觸發(fā)一次
?? ?timer11.Elapsed += new System.Timers.ElapsedEventHandler(timer_handle); // 執(zhí)行函數(shù)tiemr_handle
?? ?timer11.AutoReset = true;
?? ?timer11.Enabled = true;
?? ?timer11.Start();
}4、定時器觸發(fā)執(zhí)行函數(shù)
public int gIndex = 1;
public void timer_handle(object source, System.Timers.ElapsedEventArgs e)
{
?? ?double mpre1 = Log10(gIndex) * 300;
?? ?double mpre2 = Sin(gIndex) * 200;
?? ?//
?? ?DrawPoint(1, mpre1);
?? ?DrawPoint(2, mpre2);
?? ?gIndex++;
}效果動態(tài)圖:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
c#之圓形無標(biāo)題欄橢圓窗體的實現(xiàn)詳解
本篇文章是對c#中圓形無標(biāo)題欄橢圓窗體的實現(xiàn)方法進行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
C#實現(xiàn)通過程序自動抓取遠(yuǎn)程Web網(wǎng)頁信息的代碼
C#實現(xiàn)通過程序自動抓取遠(yuǎn)程Web網(wǎng)頁信息的代碼...2007-04-04

