C# Chart简单图形波形绘制

此次用C#绘制波形使用的是Chart控件

1、 将Chart控件拖进主界面,然后设置属性。

// 
// 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、 画线委托函数

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、 设置一个按键,然后设置按键点击触发时候的定时器Timer属性,用来触发波形产生(用控件按键触发)

private void button3_Click(object sender, EventArgs e)
{
	System.Timers.Timer timer11 = new System.Timers.Timer(400); // 每400ms触发一次
	timer11.Elapsed += new System.Timers.ElapsedEventHandler(timer_handle); // 执行函数tiemr_handle
	timer11.AutoReset = true;
	timer11.Enabled = true;
	timer11.Start();
}

4、 定时器触发执行函数

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++;
}

效果动态图:

  • 0
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值