通过MSChart实现实时曲线波形图
/// <summary> /// 初始化图表 /// </summary> private void InitChart() { //定义图表区域 this.chart1.ChartAreas.Clear(); ChartArea chartArea1 = new ChartArea("C1"); this.chart1.ChartAreas.Add(chartArea1); //定义存储和显示点的容器 this.chart1.Series.Clear(); Series series1 = new Series("S1"); series1.ChartArea = "C1"; this.chart1.Series.Add(series1); //设置图表显示样式 this.chart1.ChartAreas[0].AxisY.Minimum = 0; this.chart1.ChartAreas[0].AxisY.Maximum =100; this.chart1.ChartAreas[0].AxisX.Interval = 5; 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 = "XXX显示"; 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( "XXX {0} 显示",rb1.Text); this.chart1.Series[0].ChartType = SeriesChartType.Line; } if (rb2.Checked) { this.chart1.Titles[0].Text = string.Format("XXX {0} 显示", rb2.Text); this.chart1.Series[0].ChartType = SeriesChartType.Spline; } this.chart1.Series[0].Points.Clear(); }
评论