C#中System.Drawing制作折线图

来源:互联网 时间:1970-01-01

C#中System.Drawing制作折线图,有需要的朋友可以参考下。

核心代码:

 /// <summary> /// 创建折线图 /// </summary> /// <param name="width">所需折线图的宽度</param> /// <param name="height">所需折线图的高度</param> /// <param name="points">所需画出的点</param> /// <param name="color">折线图颜色</param> /// <returns></returns> public static Texture2D LineChart3d(ref Texture2D lc, int width,int height,PointF[] points, System.Drawing.Color color) {if (lc == null){lc = new Texture2D(width, height);}Bitmap bitmap = new Bitmap(width, height);System.Drawing.Graphics ccd = System.Drawing.Graphics.FromImage(bitmap);ccd.SmoothingMode = SmoothingMode.AntiAlias;ccd.Clear(System.Drawing.Color.Transparent);//画曲线图System.Drawing.Pen pen = new Pen(color);pen.Width = width / 100;//画点//float pWidth = width / 30;//float pHeight = width / 30;//for (int i = 0; i != points.Length; ++i)//{// points[i].X *= width;// points[i].Y = (1 - points[i].Y) * height;// ccd.FillEllipse(new SolidBrush(color), new RectangleF(points[i].X - pWidth / 2.0f, points[i].Y - pHeight / 2.0f, pWidth, pHeight));//}for (int i = 0; i < points.Length; ++i){points[i] = new PointF(points[i].X * width, points[i].Y * height);}ccd.DrawLines(pen, points);//for (int i = 0; i != points.Length - 1; ++i)//{// ccd.DrawLine(pen, points[i], points[i + 1]);//}byte[] byteArray = new byte[0];using (MemoryStream stream = new MemoryStream()){bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);stream.Close();byteArray = stream.ToArray();}lc.LoadImage(byteArray);return lc; }


版权声明:本文为博主原创文章,未经博主允许不得转载。



相关阅读:
Top