<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
在終端機器上的曲線顯示本打算用控制元件,可控制元件折騰好長時間也沒弄順,還是自己寫的好使,記錄下來後面再改進。
//繪圖部分的定義 Int32 Draw_Top;//繪畫Y起點 Int32 Draw_Left;//繪畫X起點 Int32 Draw_EdgeWidth;//X邊緣寬度 Int32 Draw_EdgeHeight;//Y邊緣高度 Int32 Draw_RangeWidth;//繪畫範圍寬度 Int32 Draw_RangeHeight;//繪畫範圍高度 Double[] XTDYData = new Double[21]; Int32 ICountDraw=0; Int32 IActualWidth, IActualHeight; Int32 Draw_AdjustX = 20; Int32 Draw_AdjustY = 20; Point StartPoint = new Point(); Point EndPoint = new Point(); Point ZeroPoint = new Point(); Int32 IScalesY = 11; Int32 IScalesX = 21; Int32 IIncrementX; Pen pSpecial = new Pen(Color.Black,1); Pen pCommon = new Pen(Color.Black,2); Font FontTitle = new Font("微軟雅黑", 12);//寫標題的字型 Font FontText = new Font("微軟雅黑", 9);//寫正文的字型 SolidBrush SBTitle = new SolidBrush(Color.Red); SolidBrush SBText = new SolidBrush(Color.Black);
在資料接收的事件中進行曲線繪製:
//顯示趨勢圖 ICountDraw = ICountDraw + 1; if (ICountDraw ==21) { for (int i=1;i<21;i++) { XTDYData[i - 1] = XTDYData[i]; } XTDYData[20]= YBDWDealWithData.TYNDianYa.dValue; ICountDraw = 20; } else { XTDYData[ICountDraw] = YBDWDealWithData.TYNDianYa.dValue; } FuncDrawYBDW();
下面是基礎函數:
public void FuncDrawYBDW() { Bitmap bmp = new Bitmap(Draw_RangeWidth, Draw_RangeHeight);//定義畫布的大小 Graphics graphics = Graphics.FromImage(bmp); FuncDrawBasePic(ref graphics); FuncDrawDynamicPic(ref graphics); Graphics g = Graphics.FromHwnd(pictureBox1.Handle); g.DrawImage(bmp, new Point(0, 0));//在記憶體中畫完後顯示在pictureBox1上,避免閃爍 } public void FuncDrawBasePic(ref Graphics YBDWCanvas) { //繪製基礎 //畫一個方框 YBDWCanvas.FillRectangle(Brushes.WhiteSmoke, Draw_Top, Draw_Left, Draw_RangeWidth, Draw_RangeHeight); //畫座標軸X pCommon.Width = 2; pCommon.Color = Color.Black; StartPoint.X = Draw_Left + Draw_AdjustX; StartPoint.Y = Draw_Top + Draw_RangeHeight - Draw_AdjustY * 2; EndPoint.X = Draw_Left + Draw_RangeWidth - Draw_AdjustX * 2; EndPoint.Y = Draw_Top + Draw_RangeHeight - Draw_AdjustY * 2; YBDWCanvas.DrawLine(pCommon, StartPoint, EndPoint); IActualWidth = EndPoint.X - StartPoint.X; YBDWCanvas.DrawString("X", FontText, SBText, EndPoint.X, EndPoint.Y - 8); //畫箭頭 StartPoint.X = EndPoint.X - 8; StartPoint.Y = EndPoint.Y - 4; YBDWCanvas.DrawLine(pCommon, StartPoint, EndPoint); StartPoint.X = EndPoint.X - 8; StartPoint.Y = EndPoint.Y + 4; YBDWCanvas.DrawLine(pCommon, StartPoint, EndPoint); //畫座標軸Y pCommon.Width = 2; pCommon.Color = Color.Black; StartPoint.X = Draw_Left + Draw_AdjustX; StartPoint.Y = Draw_Top + Draw_AdjustY; EndPoint.X = Draw_Left + Draw_AdjustX; EndPoint.Y = Draw_Top + Draw_RangeHeight - Draw_AdjustY * 2; YBDWCanvas.DrawLine(pCommon, StartPoint, EndPoint); IActualHeight = EndPoint.Y - StartPoint.Y; ZeroPoint = EndPoint; //畫畫箭頭 EndPoint.X = StartPoint.X - 4; EndPoint.Y = StartPoint.Y + 8; YBDWCanvas.DrawLine(pCommon, StartPoint, EndPoint); EndPoint.X = StartPoint.X + 4; EndPoint.Y = StartPoint.Y + 8; YBDWCanvas.DrawLine(pCommon, StartPoint, EndPoint); YBDWCanvas.DrawString("Y", FontText, SBText, EndPoint.X, EndPoint.Y - 8); //畫X刻度 pSpecial.Width = 1; pSpecial.DashStyle = DashStyle.Custom; pSpecial.DashPattern = new float[] { 1f, 1f }; IIncrementX = IActualWidth / IScalesX; for (int i = 1; i < IScalesX; i = i + 1) { StartPoint.X = ZeroPoint.X + IIncrementX * i; StartPoint.Y = ZeroPoint.Y - 2; EndPoint.X = StartPoint.X; EndPoint.Y = StartPoint.Y - IActualHeight - 2; YBDWCanvas.DrawLine(pSpecial, StartPoint, EndPoint); //寫標識字 if (i % 2 == 0) { YBDWCanvas.DrawString(i.ToString(), FontText, SBText, StartPoint.X - 6, StartPoint.Y + 4); } } //畫Y刻度 Int32 IIncrementY = IActualHeight / IScalesY; for (int i = 1; i < IScalesY; i = i + 1) { StartPoint.X = ZeroPoint.X; StartPoint.Y = ZeroPoint.Y - IIncrementY * i; EndPoint.X = StartPoint.X + IActualWidth; EndPoint.Y = StartPoint.Y; YBDWCanvas.DrawLine(pSpecial, StartPoint, EndPoint); //寫標識字 if (i % 2 == 0) { YBDWCanvas.DrawString((i - 1).ToString(), FontText, SBText, StartPoint.X - 12, StartPoint.Y + 4); } } //寫標題 //Rectangle YBDWMessRect = new Rectangle(SX, SY, MessageDotRadius * 2, MessageDotRadius * 2);//圓的大小 //YBDWCanvas.FillEllipse(SBTitle, YBDWMessRect); //畫連線線 YBDWCanvas.DrawString(SDrawTitle, FontTitle, SBTitle, 100,30); } public void FuncDrawDynamicPic(ref Graphics YBDWCanvas) { //準備實際畫線的資料 Point[] XTDYPoints =new Point[21];//系統電壓資料 for (int i = 0; i < IScalesX; i = i + 1) { XTDYPoints[i].X = ZeroPoint.X + IIncrementX * i; XTDYPoints[i].Y = ZeroPoint.Y - (int)((XTDYData[i]/IActualHeight)*6000); } pSpecial.Width = 3; pSpecial.Color = Color.Red; YBDWCanvas.DrawCurve(pSpecial, XTDYPoints, 3.0F); }
實際效果圖:
點選不同的文字進行相應的實時動態圖的顯示。
以上就是C#繪製實時曲線圖的方法詳解的詳細內容,更多關於C#實時曲線圖的資料請關注it145.com其它相關文章!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45