Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to draw real-time curve with C #

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to draw a real-time curve in C#". The content in the article is simple and clear, and it is easy to learn and understand. let's follow the editor's train of thought to study and learn "how to draw a real-time curve in C#".

1. To do a debugging tool to collect sensor data and display. Draw the curve and pay attention to the inversion of the coordinates and the tension of the line. The curves in the project are displayed from right to left, and the coordinates of the lines are placed in list, as shown in the following figure:

two。 Upper code

The public class DrawingCurve {private Graphics graphics; / / Graphics class provides a method for drawing objects to the display device private Bitmap bitmap; / / Bitmap object private int timeLine = 60Tracabash 60s private int canvasWidth = 600bp / canvas length private int sliceCount = 0Example / number of tick segments = timeLine private int xSlice = 10Example width of X-axis scale private int xSliceHeight = 10 / / X axis calibration height private float tension = 0.5f; / / tension coefficient private bool showX = true; private bool showY = true; private bool showZ = true; / / Queue que = new Queue (); / / curve fifo / constructor / public DrawingCurve () {this.xSlice = this.canvasWidth / timeLine } / draw canvas / public Bitmap DrawCanvas (int width, int height,List points) {if (bitmap! = null) {bitmap.Dispose () Bitmap = null;} bitmap = new Bitmap (width, height); graphics = Graphics.FromImage (bitmap); graphics.FillRectangle (Brushes.Black, new Rectangle (0,0, width, height)); graphics.Transform = new Matrix (1,0,0,-1,0,0) / / positive Y axis, graphics.TranslateTransform (0, height / 2, MatrixOrder.Append) in X direction; Pen pen = new Pen (Color.Red, 1); pen.DashStyle = DashStyle.Custom; pen.DashPattern = new float [] {2,2}; graphics.DrawLine (pen, new Point (0, height / 4), new Point (width, height / 4)) Graphics.DrawLine (pen, new Point (0, height /-4), new Point (width, height /-4); graphics.DrawLine (new Pen (Color.GreenYellow,1), new Point (0,0), new Point (width, 0); graphics.DrawString ("0", new Font ("Vendara", 10), Brushes.White, new Point (0,-15)) Graphics.DrawString ("+", new Font ("Vendara", 10), Brushes.White, new Point (0, height / 4)); graphics.DrawString ("-", new Font ("Vendara", 10), Brushes.White, new Point (0, height /-4-15)); graphics.Transform = new Matrix (1,0,0,1,0,0) / / positive Y axis, right graphics.TranslateTransform (0, height/2, MatrixOrder.Append); graphics.DrawString ("- 59s", new Font ("Vendara", 8), Brushes.White, new Point (0, height/2-15); graphics.DrawString ("0s", new Font ("Vendara", 8), Brushes.White, new Point (width-20, height/2-15)); for (int I = 0) I < timeLine; iTunes +) {int scale = I * xSlice; graphics.DrawLine (new Pen (new SolidBrush (Color.Blue)), 0 + scale, 0 + xSliceHeight * 0.1f, 0 + scale, 0-xSliceHeight * 0.1f);} graphics.Transform = new Matrix (- 1,0,0,-1,0,0) / / positive Y axis, graphics.TranslateTransform (width, height / 2, MatrixOrder.Append) in X direction; if (showX) DrawX (graphics, points); if (showY) DrawY (graphics, points); if (showZ) DrawZ (graphics, points); graphics.Dispose (); return bitmap } # region draw curves private void DrawX (Graphics graphics, List points) {Pen CurvePen = new Pen (Color.Cyan, 2); PointF [] CurvePointF = new PointF [points.Count]; float keys = 0; float values = 0; for (int I = 0; I < points.Count) Keys +) {keys = xSlice * I; values = 10 * (points [I] / 10); CurvePointF [I] = new PointF (keys, values);} graphics.DrawCurve (CurvePen, CurvePointF, this.tension) } private void DrawY (Graphics graphics, List points) {Pen CurvePen = new Pen (Color.Purple, 2); PointF [] CurvePointF = new PointF [points.Count]; float keys = 0; float values = 0; for (int I = 0; I < points.Count; I +) {keys = xSlice * I Values = 10 * (points [I] / 10); CurvePointF [I] = new PointF (keys, values);} graphics.DrawCurve (CurvePen, CurvePointF, this.tension);} private void DrawZ (Graphics graphics, List points) {Pen CurvePen = new Pen (Color.OrangeRed, 2); PointF [] CurvePointF = new PointF [points.Count] Float keys = 0; float values = 0; for (int I = 0; I < points.Count; iTunes +) {keys = xSlice * I; values = 10 * (points [I] / 10); CurvePointF [I] = new PointF (keys, values) } graphics.DrawCurve (CurvePen, CurvePointF, this.tension);} / curve switch / public void HideCurve (string _ xyz,bool show) {switch (_ xyz) {case "x": showX = show Break; case "y": showY = show; break; case "z": showZ = show; break; default: break }} # endregion}

Use ThreadStart to call on 3.UI, set sleep time as needed, and set pictureBox display at the same time.

Thank you for your reading, the above is the content of "how to draw the real-time curve of C#". After the study of this article, I believe you have a deeper understanding of how to draw the real-time curve of C#. The specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report