永发信息网

如何使用c#输入数据生成直方图 或者用数据库也可以

答案:5  悬赏:80  手机版
解决时间 2022-01-01 20:47
  • 提问者网友:蔚蓝的太阳
  • 2021-12-31 19:55
把散点 生成曲线,并且曲线上每个点都可以调用数据,求教 谢谢了

顺便问下 用哪个数据库相对简单, 小程序 数据不多
最佳答案
  • 五星知识达人网友:梦中风几里
  • 2021-12-31 20:36
拜托!直接用Chart控件,在“数据”分支下面。
全部回答
  • 1楼网友:猎心人
  • 2022-01-01 00:38
GDI+,sqlsever
  • 2楼网友:上分大魔王
  • 2021-12-31 23:25
用chart控件, chart1.datasource = ds;//ds就是你的数据集 chart1.databind(); 其他的属性你自己设置就可以了,很简单的。
  • 3楼网友:笑迎怀羞
  • 2021-12-31 21:46
Access相对比较简单,小程序一般用它吧! 我用C#画过饼图和柱形图,还没滑过曲线图,不过原理应该都一样,标好点再Drawline罢了。
  • 4楼网友:从此江山别
  • 2021-12-31 20:56
用控件不是很简单吗?????? //画饼形图 public static void draw_pie() { Bitmap myImage = new Bitmap(600, 300); Graphics g = Graphics.FromImage(myImage); g.Clear(Color.White); //绘画图形中指定的位置,以指定的字体,表示为图标 g.DrawString("销售情况表", new Font("宋体", 16), Brushes.Black, new Point(5, 5)); Point rec = new Point(513, 30); Point dec = new Point(540, 30); Point txt = new Point(565, 30); g.DrawString("单位:件", new Font("宋体", 9), Brushes.Black, new Point(512, 12)); for (int i = 0; i < months.Length; i++) { g.FillRectangle(new SolidBrush(get_color(i)), rec.X, rec.Y, 20, 10); g.DrawRectangle(Pens.Black, rec.X, rec.Y, 20, 10); g.DrawString(months[i].ToString(), new Font("宋体", 9), Brushes.Black, dec); //绘制右边的文字 g.DrawString(number[i].ToString(), new Font("宋体", 9), Brushes.Black, txt); rec.Y += 15; dec.Y += 15; txt.Y += 15; } int total = 0; float currentAanle = 0; float startAngle = 0; for (int i = 0; i < number.Length; i++) { total += number[i]; } for (int i = 0; i < number.Length; i++) { if (i == number.Length) { currentAanle = 360 - startAngle; } else { int temp = number[i]; currentAanle = (temp * 360) / total; } g.DrawPie(Pens.Black, 100, 40, 250, 250, startAngle, currentAanle); g.FillPie(new SolidBrush(get_color(i)), 100, 40, 250, 250, startAngle, currentAanle); startAngle += currentAanle; } Pen pen = new Pen(Color.Black, 2); g.DrawRectangle(pen, 1, 1, 598, 298); myImage.Save(System.Web.HttpContext.Current.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif); myImage.Dispose(); g.Dispose(); pen.Dispose(); } //画柱形图 public static void draw_rec() { Bitmap myImage = new Bitmap(600,400); Graphics g = Graphics.FromImage(myImage); g.Clear(Color.White); //绘画图形中的指定位置,以指定的字体,表示为图标 g.DrawString("年销售一览表",new Font("宋体",16),Brushes.Black,new Point(5,5)); Point rec = new Point(515, 30); Point dec = new Point(540, 30); Point txt = new Point(565, 30); g.DrawString("单位:件", new Font("宋体", 9), Brushes.Black, new Point(525, 12)); for (int i = 0; i < months.Length; i++) { g.DrawRectangle(Pens.Blue, rec.X, rec.Y, 20, 10); g.FillRectangle(new SolidBrush(get_color(i)),rec.X,rec.Y,20,10); g.DrawString(months[i].ToString(), new Font("宋体", 9), Brushes.Black, dec); //绘制右边的文字 g.DrawString(number[i].ToString(), new Font("宋体", 9), Brushes.Black, txt); rec.Y += 15; dec.Y += 15; txt.Y += 15; } //数据库中获取数据,计算数量 int barwidth = 30; int scale = 1; for (int i = 0; i < number.Length;i++ ) { g.DrawRectangle(Pens.Black,(i*barwidth)+15,398-(number[i]*scale),20,(number[i]*scale)+5); g.FillRectangle(new SolidBrush(get_color(i)),(i*barwidth)+15,398-(number[i]*scale),20,(number[i]*scale)+5); g.DrawString(number[i].ToString(),new Font("宋体",9),Brushes.Black,(i*barwidth)+20,385-(number[i]*scale)); } Pen mypen = new Pen(Color.Black,2); g.DrawRectangle(mypen,1,1,598,398); myImage.Save(System.Web.HttpContext.Current.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif); myImage.Dispose(); g.Dispose(); mypen.Dispose(); } //画折线图 public static void draw_zxt() { //画图初始化 Bitmap myimage = new Bitmap(500, 500); Graphics g = Graphics.FromImage(myimage); g.Clear(Color.White); PointF cpt = new PointF(40, 420);//中心点 PointF[] xpt = new PointF[3] { new PointF(cpt.Y + 15, cpt.Y), new PointF(cpt.Y, cpt.Y - 8), new PointF(cpt.Y, cpt.Y + 8) };//x轴三角形 PointF[] ypt = new PointF[3] { new PointF(cpt.X, cpt.X - 15), new PointF(cpt.X - 8, cpt.X), new PointF(cpt.X + 8, cpt.X) };//y轴三角形 g.DrawString("月销售量图表", new Font("宋体", 14), Brushes.Black, new PointF(cpt.X + 60, cpt.X));//图表标题 //画x轴 g.DrawLine(Pens.Black, cpt.X, cpt.Y, cpt.Y, cpt.Y); g.DrawPolygon(Pens.Black, xpt); g.FillPolygon(new SolidBrush(Color.Black), xpt); g.DrawString("月份", new Font("宋体", 12), Brushes.Black, new PointF(cpt.Y + 10, cpt.Y + 10)); //画y轴 g.DrawLine(Pens.Black, cpt.X, cpt.Y, cpt.X, cpt.X); g.DrawPolygon(Pens.Black, ypt); g.FillPolygon(new SolidBrush(Color.Black), ypt); g.DrawString("单位(件)", new Font("宋体", 12), Brushes.Black, new PointF(0, 7)); for (int i = 1; i <= 12; i++) { //画y轴刻度 if (i < 12) { g.DrawString((i * 10).ToString(), new Font("宋体", 11), Brushes.Black, new PointF(cpt.X - 30, cpt.Y - i * 30 - 6)); g.DrawLine(Pens.Black, cpt.X - 3, cpt.Y - i * 30, cpt.X, cpt.Y - i * 30); } //画x轴月份 g.DrawString(months[i - 1].Substring(0, 1), new Font("宋体", 11), Brushes.Black, new PointF(cpt.X + i * 30 - 5, cpt.Y + 5)); g.DrawString(months[i - 1].Substring(1, 1), new Font("宋体", 11), Brushes.Black, new PointF(cpt.X + i * 30 - 5, cpt.Y + 20)); if (months[i - 1].Length > 2) g.DrawString(months[i - 1].Substring(2, 1), new Font("宋体", 11), Brushes.Black, new PointF(cpt.X + i * 30 - 5, cpt.Y + 35)); //画点 g.DrawEllipse(Pens.Black, cpt.X + i * 30 - 1.5f, cpt.Y - number[i - 1] * 3 - 1.5f, 3, 3); g.FillEllipse(new SolidBrush(Color.Black), cpt.X + i * 30 - 1.5f, cpt.Y - number[i - 1] * 3 - 1.5f, 3, 3); //画数值 g.DrawString(number[i - 1].ToString(), new Font("宋体", 11), Brushes.Black, new PointF(cpt.X + i * 30, cpt.Y - number[i - 1] * 3)); //画折线 if (i > 1) g.DrawLine(Pens.Red, cpt.X + (i - 1) * 30, cpt.Y - number[i - 2] * 3, cpt.X + i * 30, cpt.Y - number[i - 1] * 3); } //保存输出图片 myimage.Save(System.Web.HttpContext.Current.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif); // PictureBox1.Image = bmap; }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯