c++画椭圆正方形扇形代码
C语言常用的小程序代码

1、Fibonacci函数(递归)#include"stdio.h"int fo(int n){int f;if(n==2||n==1)f=1;elsef=fo(n-1)+fo(n-2);//递归调用return f;}void main(){int i;for(i=1;i<=20;i++){printf("%-6d",fo(i));if(i%10==0)printf("\n");}}2、计算π值#include <stdio.h>#include <math.h>float pai(float e){float n,t,pi;int s;s=1;n=1.0;t=1.0;pi=0.0;while(fabs(t)>e){pi=pi+t;n+=2;s=-s;t=s/n;}return pi*4;}{float pi,eps=0.00005;pi=pai(eps);printf("%f\n",pi);}3、两个数的大小#include <stdio.h>int max(int x,int y)//判断大小{if(x>y)return x;elsereturn y;}main(){int x,y,m;printf("输入两个数:\n");scanf("%d %d",&x,&y);m=max(x,y);printf("最大值是%d\n",m);printf("****End****\n");}4、数组中的元素排序,最大值,最小值#include<stdio.h>void paixu(int x[],int n){ //排序int t,i,k,j;printf("\n");for(i=0;i<n-1;i++){k=i;for(j=i+1;j<n;j++){if(x[i]>x[j]){t=x[k];x[k]=x[j];x[j]=t;}}}}int maxn(int x[],int n){int i,max,t;//求最大值max=x[0];for(i=1;i<n;i++){if(max<x[i]){t=x[i];x[i]=max;max=t;}}return max;}int minn(int x[],int n){int i,min,t;//求最小值min=x[0];for(i=1;i<n;i++){if(min>x[i]){t=x[i];x[i]=min;min=t;}}return min;}main(){int a[100],i,n;printf("输入n(n<=100)确定数组维数:");scanf("%d",&n);for(i=0;i<n;i++){scanf("%d",&a[i]);}paixu(a,n);printf("排序后的数组是:\n");for(i=0;i<n;i++){printf("%-4d",a[i]);}printf("\n");printf("该数组中的最大值是%d\n",maxn(a,n));printf("该数组中的最小值是%d\n",minn(a,n));}5、圆的面积和周长#include<stdio.h>#define pi 3.14float circle_C(float r) //计算圆的周长{float c;c=2*pi*r;return c ;}float circle_S(float r) //计算面积{float s;s=pi*r*r;return s;}main(){float r,c,s;printf("输入圆的半径r:");scanf("%f",&r);c=circle_C( r); //调用函数计算周长printf("圆的周长是%f\n",c);s=circle_S( r); //调用函数计算面积printf("圆的面积是%f\n",s);}6、最小公倍数#include"stdio.h"int fun(int x,int y){int t,r,min;//调用函数求最小公倍数if(x<y){t=x;x=y;y=t;}r=x%y;if(r==0) printf("最大公约数是%d\n",y);else{while(r!=0){ x=y;y=r;r=x%y;}printf("最大公约数是%d\n",y);}return y;}main(){int x,y,m,r;printf("输入两个数:\n");scanf("%d%d",&x,&y);printf("x=%d y=%d\n",x,y);m=x*y;r=fun(x,y);m=m/r;printf("%d和%d最小公倍数是:%d\n",x,y,m); }7、杨辉三角#include"stdio.h"#define N 15void setdata(int (*s)[N],int n){int i,j;for(i=0;i<n;i++)//给第一个和最后一个赋值为1 {s[i][i]=1;s[i][0]=1;}for(i=2;i<n;i++)//从第二行的第二个数开始赋值{for(j=1;j<i;j++){s[i][j]=s[i-1][j-1]+s[i-1][j];}}}void outdata(int s[][N],int n)//输出杨辉三角{int i,j;printf("输出杨辉三角:\n");for(i=0;i<n;i++){for(j=0;j<=i;j++)printf("%-4d",s[i][j]);printf("\n");}}void main(){int y[N][N],n=10;setdata(y,n);outdata(y,n);}。
C++程序:用EasyX绘制正方形及对角线

C++程序:用EasyX绘制正方形及对角线(一)设计C++程序,在窗体中心绘制一个正方形,用红色虚线画出该正方形的两条对角线。
(二)程序源代码如下:#include<graphics.h>#include<conio.h>int main(){initgraph(300,200);SetWindowText(GetHWnd(),"EasyX图形编程");line(125,75,175,75);moveto(175,75);lineto(175,125);lineto(125,125);lineto(125,75);setlinecolor(RED);setlinestyle(PS_DASH);line(175,75,125,125);line(125,75,175,125);getch();closegraph();return 0;}(三)说明:1、使用EasyX图形编程,必须包含头文件graphics.h;2、使用getch()函数使程序阻塞,必须包含头文件conio.h;3、在main()函数体内,第一条语句就是设置窗体大小,使用的函数是initgraph(参数1,参数2),参数1是窗体宽,参数2是窗体高,对应横坐标和纵坐标,其单位是像素(piex);4、函数SetWindowText(GetHWnd(),"EasyX图形编程")作用是设置窗体的标题;5、绘制直线函数是line(参数1,参数2,参数3,参数4),参数1是直线起点的横坐标,参数2是直线起点的纵坐标,参数3直线终点的横坐标,参数4直线终点的纵坐标;6、moveto(参数1,参数2)函数,作用是将绘制直线的起点移动到指定的点。
参数1是起点的横坐标,参数2是起点的纵坐标;7、setlinecolor(颜色常量)函数,作用是设置线条的颜色;8、setlinestyle(PS_DASH)函数,作用是设置线条的样式,为虚线;9、closegraph()函数,作用是关闭窗体。
C语言写椭圆

d1+=b*b*(2*x+3)+a*a*((-2)*y+2);
x++;
y--;
}
putpixel(x+300,y+200,color);
putpixel(-x+300,-y+200,color);
putpixel(-x+300,y+200,color);
putpixel(x+300,-y+200,color);
case '3': line(110,120,200,240);break;
case '4': MidBresenhamllipse(34,55,6);break;
case '5': cs_Ellipse(120,240,20,120,21);break;
case '6': ellipse(110,250,0,360,100,40);break;
else
length=abs(y2-y1);
increx=(x2-x1)/length;
increy=(y2-y1)/length;
x=x1;
y=y1;
for(i=1;i<=length;i++)
{ xx=x+0.5;
yy=y+0.5;
putpixel((int)xx,(int)yy,color);
putpixel(-x+300,-y+200,color);
putpixel(-x+300,y+200,color);
putpixel(x+300,-y+200,color);
C语言6行代码画圆

C语⾔6⾏代码画圆 这⼀⽅法是受到milo⼤神⽤C语⾔画⼼的启发⽽想到的。
代码如下:#include<stdio.h>int main(){for(double l=1;l>-1;l-=0.05,printf("\n"))for(double w=1;w>-1;w-=0.025)printf((l*l + w*w<=1)?"=":"");} 效果: 事实上,代码的逻辑和背景知识是很简单的,就是从左到右,从上到下,⽤等号填充⼀个圆⽽已。
我们知道,圆⽅程的标准形式为: 当a b r的值确定后,圆也就完全确定了,为了简化⽅程,我们令a b 为0,r为1,则该圆全部落-1<x<1,-1<y<1的范围中,这也是l和w范围的来源。
接下来,很⾃然的就要思考字符数量了,⼀般⽽⾔,半⾓⽂字的长宽⽐为1:2(很汗颜,这也是从milo⼤神的⽂章中知道的),所以宽度增量设置为长度的⼀半就⾏了,如果为1:1的话,会得到⼀个椭圆。
为什么增量设置为0.05和0.025呢?⾸先,增量的设置的越⼩,得到的圆就越圆,但是过⼤的话⼀屏⽆法显⽰完全,0.05和0.025是⼀个较优值,读者也可以尝试其他值。
整段代码中最难理解的⼀句应该是printf((l*l + w*w<1)?"=":""); 其实只是⼀个简单的双⽬运算符应⽤,意思是,如果该点落于圆中,则⽤“=”符号填充,否则⽤空格代替。
说到底只是数学的简单应⽤罢了,理论上来说,只要有相对应的图像⽅程,这段代码也可以进⾏相应的修改从⽽输出对应图像。
读者有兴趣不妨试试:-)。
3种c#画图方法

3种c#画图方法1 //描绘曲线//创建曲线中的点Point point1 = new Point(68, 420);Point point2 = new Point(71, 410);Point point3 = new Point(74, 423);Point point4 = new Point(77, 412);Point point5 = new Point(80, 400);Point point6 = new Point(90, 380);Point point7 = new Point(100, 350);Point point8 = new Point(120, 320);Point[] curvePoints = { point1, point2, point3, point4, point5, point6, point7, point8 };GraphicsPath myPath = new GraphicsPath();//AddCurve(点阵,起点,终点,弯曲程度)myPath.AddCurve(curvePoints, 0, 7, 0.8f);Pen myPen = new Pen(Color.Red, 1);IMG.DrawPath(myPen, myPath);---------------------------------------------------------------------------------------------2 c#.net画曲线图(坐标)using System.Drawing.Imaging;using System.Drawing.Drawing2D;//数据/月份public ArrayList arrData=new ArrayList();public ArrayList arrMonth=new ArrayList();//定义幕布高宽private int iCanvasWidth=400;private int iCanvasHeight=300;//x轴的间距private int iX=30;//y轴间距private int iY=15;public void InitArray(){for(int i=0;i<6;i++)arrMonth.Add(i+1);arrData.Add(200);arrData.Add(180);arrData.Add(285);arrData.Add(290);arrData.Add(275);arrData.Add(350);}// //pen 画线// Pen myPen = new Pen(Color.Black);// Graphics g = this.CreateGraphics();// g.DrawEllipse(myPen, 20, 30, 10, 50);//// Graphics g1 = this.CreateGraphics();// SolidBrush myBrush = new SolidBrush(Color.Red);// g1.FillEllipse(myBrush,20,30,40,40);// g1.FillRectangle(myBrush,70,70,10,30);this.InitArray();Bitmap bitmap= new Bitmap(iCanvasWidth, iCanvasHeight,PixelFormat.Format24bppRgb);//Graphics g=Graphics.FromImage(bitmap);Graphics g=this.CreateGraphics();g.Clear(Color.White);Font font = new Font("MS UI Gothic",12);SolidBrush brush = new SolidBrush(Color.Black);Pen pen = new Pen(Color.Black);pen.EndCap = LineCap.ArrowAnchor;pen.DashStyle = DashStyle.Solid;//坐标轴g.DrawLine(pen,20,220,420,220);g.DrawLine(pen,20,220,20,20);//x轴标格g.DrawLine(Pens.Black,20+iX*1,220,20+iX*1,220-2);g.DrawLine(Pens.Black,20+iX*2,220,20+iX*2,220-2);g.DrawLine(Pens.Black,20+iX*3,220,20+iX*3,220-2);g.DrawLine(Pens.Black,20+iX*4,220,20+iX*4,220-2);g.DrawLine(Pens.Black,20+iX*5,220,20+iX*5,220-2);g.DrawLine(Pens.Black,20+iX*6,220,20+iX*6,220-2);//y轴标格g.DrawLine(Pens.Black, 20, 220 - iY*1, 20 + 2, 220 - iY*1);g.DrawLine(Pens.Black, 20, 220 - iY*2, 20 + 2, 220 - iY*2);g.DrawLine(Pens.Black, 20, 220 - iY*3, 20 + 2, 220 - iY*3);g.DrawLine(Pens.Black, 20, 220 - iY*4, 20 + 2, 220 - iY*4);g.DrawLine(Pens.Black, 20, 220 - iY*5, 20 + 2, 220 - iY*5);g.DrawLine(Pens.Black, 20, 220 - iY*6, 20 + 2, 220 - iY*6); //double dblX1=20;double dblY1=220;for(int i=0;i<arrdata.count;i++)< p="">{double dblData=Convert.ToDouble(arrData[i]);double dblY2=220-dblData*15/200;double dblX2=20+iX*Convert.ToInt32(arrMonth[i]);if(i!=0){if(i<arrdata.count-1)< p="">{g.DrawLine(Pens.Black,float.Parse(dblX1.ToString()),float.Pars e(dblY1.ToString()),float.Parse(dblX2.T oString()),float.Parse(dblY2.ToString()));}else{g.DrawLine(pen,float.Parse(dblX1.T oString()),float.Parse(dblY1.ToString()),float.Parse( dblX2.ToString()),float.Parse(dblY2.ToStri ng()));}}dblX1=dblX2;dblY1=dblY2;}}}}-------------------------------------------------------------------------------------------------------C#画折线图一例在.net中,微软给我们提供了画图类(system.drawing.imaging),在该类中画图的基本功能都有。
几个简单分形图形的C语言实现

sin 600 cos 600 0
x4
y4 1 x3Fra biblioteky30 1 0 0 0 0 1 0 1 x y2 1 2
1.3. 程序设计过程 (一) 迭代过程函数
void
koch(double x0, double y0, double x1, double y1, int k) /* 给出直线 F0 的两个端点坐标(x0,y0)和(x1,y1),并且定义迭代次数为 k 次*/
x2
y2 1 x1
y1
1 0 0 0 0 1 3 1 0 0 0 1 0 1 0 1 0 1 0 0 3 x y 1 0 1 x y 1 0 0 0 0 0
x3
y3 1 x1
printf(”Please input the value of the positive integer n (n<9):”);
scanf(“%d”, &n); setcolor(GREEN); sierpinski(20, 20, 470, 470, n); getch(); closegraph(); } 2.4. 生成图形显示
/*输入迭代次数 n*/ /*设置 sierpinski 三角形颜色为绿色*/ /*画 sierpinski 三角形*/
/*关闭图形系统*/
图 2.4 迭代四次后生成的 Sierpinski 三角形
图 2.5 迭代六次后生成的 Sierpinski 三角形
分形(三)
3.1. 绘制桧树分形小枝的生成元
{
double x2, y2, x3, y3, x4, y4; x2=2.0/3*x0+1.0/3*x1;
中小学Python教案-绘制正方形(海龟turtle)

Python编程—绘制正方形-turtle海龟编辑器一、教学目标:1.知识与技能:学生能够理解并运用Python中的循环结构。
2.过程与方法:学生能够通过项目实践,学会使用turtle库绘制图形。
3.情感态度价值观:培养学生对编程的兴趣,增强学生的动手实践能力和创新精神。
二、教学内容:1.turtle库的介绍:介绍turtle库的基本概念和使用方法。
2.循环结构:讲解for循环的语法和用法。
3.绘制正方形:使用turtle库和for循环绘制一个正方形。
三、教学重点与难点:●重点:理解for循环的概念,掌握turtle库的基本用法。
●难点:将for循环与turtle库结合使用,绘制出正方形。
四、教学准备:1.安装有Python和turtle库的计算机。
2.投影仪或黑板,用于展示代码和讲解。
五、教学步骤:1. 导入新课(5分钟)●活动:通过一个简单的“指挥乌龟”游戏来引入turtle库。
老师在黑板上画出一只“乌龟”,然后学生通过指令来“指挥”乌龟移动,比如前进、左转、右转等。
●讨论:讨论游戏中的指令如何转化为编程语言,引出turtle库的使用。
2. turtle库的介绍(10分钟)●讲解:简要介绍turtle库的基本概念和使用方法。
●演示:通过一个简单的例子,演示如何使用turtle库绘制一条直线。
3. 循环结构(10分钟)●讲解:讲解for循环的语法和用法。
●示例:通过一个简单的例子,演示如何使用for循环重复执行一系列操作。
4. 绘制正方形(10分钟)●引导:引导学生思考如何使用for循环重复绘制四条边。
●实践:让学生尝试编写代码,绘制一个正方形。
5. 项目实践(5分钟)●任务:让学生尝试修改代码,绘制不同大小的正方形。
●探索:引导学生思考如何改变正方形的大小和颜色。
6. 总结与展示(5分钟)●分享:让学生展示自己的作品,分享自己在编程过程中遇到的问题和解决方法。
●点评:对学生的作品进行点评,总结本节课的学习内容。
C#绘制统计图(柱状图,折线图,扇形图)--转载

C#绘制统计图(柱状图,折线图,扇形图)--转载转⾃:,侵删统计图形种类繁多, 有柱状图, 折线图, 扇形图等等, ⽽统计图形的绘制⽅法也有很多, 有Flash制作的统计图形, 有⽔晶报表⽣成统计图形, 有专门制图软件制作, 也有编程语⾔⾃⼰制作的;这⾥我们⽤就C# 制作三款最经典的统计图: 柱状图, 折线图和扇形图;既然是统计, 当然需要数据, 这⾥演⽰的数据存于Sql Server2000中, 三款统计图形都是动态⽣成. 其中柱状图我会附上制作步骤, 其他两款统计图直接附源码.说明: 需求不⼀样, 统计图形绘制后的显⽰效果也不⼀样, ⽐如这⾥柱状图的主要需求是为了⽐较每⼀期报名⼈数与通过⼈数的差, 因此会把两根柱⼦放在⼀起会使⽐较结果⼀⽬了然. 因此⼤家可以根据需要灵活绘制.⼀. 柱状图的绘制.绘制步骤如下:1. 定义绘图⽤到的类.int height = 500, width = 700;Bitmap image = new Bitmap(width, height);Graphics g = Graphics.FromImage(image);Pen mypen = new Pen(brush, 1);2. 绘制图框.g.FillRectangle(Brushes.WhiteSmoke, 0, 0, width, height);3. 绘制横向坐标线for (int i = 0; i < 14; i++){g.DrawLine(mypen, x, 80, x, 340);x = x + 40;}4. 绘制纵向坐标线for (int i = 0; i < 9; i++){g.DrawLine(mypen, 60, y, 620, y);y = y + 26;}5. 绘制横坐标值String[] n = { "第⼀期", "第⼆期", "第三期", "第四期", "全年" };for (int i = 0; i < 7; i++){g.DrawString(n[i].ToString(), font, Brushes.Blue, x, 348);x = x + 78;}6. 绘制纵坐标值String[] m = {"250","225", "200", "175", "150", "125", "100“};for (int i = 0; i < 10; i++){g.DrawString(m[i].ToString(), font, Brushes.Blue, 25, y);y = y + 26;}7. 定义数组存储数据库中统计的数据int[] Count1 = new int[7]; //存储从数据库读取的报名⼈数int[] Count2 = new int[7]; //存储从数据库读取的通过⼈数8. 从数据库中读取报名⼈数与通过⼈数SqlConnection Con = new SqlConnection("Server=(Local);Database=committeeTraining;");Con.Open();string cmdtxt2 = "SELECT * FROM ##Countwhere Company='" + ****+ "'";SqlDataAdapter da = new SqlDataAdapter(cmdtxt2, Con);DataSet ds = new DataSet();da.Fill(ds);9. 将读取的数据存储到数组中Count1[0] = Convert.ToInt32(ds.Tables[0].Rows[0][“count1”].ToString()); Count1[1] = Convert.ToInt32(ds.Tables[0].Rows[0][“count3”].ToString()); Count2[0] = Convert.ToInt32(ds.Tables[0].Rows[0][“count2”].ToString()); Count2[1] = Convert.ToInt32(ds.Tables[0].Rows[0]["count4"].ToString());10.定义画笔和画刷准备绘图x = 80;Font font2 = new System.Drawing.Font("Arial", 10, FontStyle.Bold);SolidBrush mybrush = new SolidBrush(Color.Red);SolidBrush mybrush2 = new SolidBrush(Color.Green);11. 根据数组中的值绘制柱状图(1)第⼀期报名⼈数g.FillRectangle(mybrush, x, 340 - Count1[0], 20, Count1[0]);g.DrawString(Count1[0].ToString(), font2,Brushes.Red, x, 340 - Count1[0] - 15);(2) 第⼀期通过⼈数x = x + 20;g.FillRectangle(mybrush2, x, 340 - Count2[0], 20, Count2[0]);g.DrawString(Count2[0].ToString(), font2,Brushes.Green, x, 340 - Count2[0] - 15);12. 将图形输出到页⾯.System.IO.MemoryStream ms = newSystem.IO.MemoryStream();image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); Response.ClearContent();Response.ContentType = "image/Jpeg";Response.BinaryWrite(ms.ToArray());最终柱状图的效果图:柱状图的完整代码:View Code⼆. 折线统计图的绘制效果:折线图的完整代码:private void CreateImage(){int height = 480, width = 700;Bitmap image = new Bitmap(width, height);Graphics g = Graphics.FromImage(image);try{//清空图⽚背景⾊g.Clear(Color.White);Font font = new System.Drawing.Font("Arial", 9, FontStyle.Regular);Font font1 = new System.Drawing.Font("宋体", 20, FontStyle.Regular);Font font2 = new System.Drawing.Font("Arial", 8, FontStyle.Regular);LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.Blue, 1.2f, true);g.FillRectangle(Brushes.AliceBlue, 0, 0, width, height);Brush brush1 = new SolidBrush(Color.Blue);Brush brush2 = new SolidBrush(Color.SaddleBrown);g.DrawString(this.ddlTaget.SelectedItem.Text + " " + this.ddlYear.SelectedItem.Text +" 成绩统计折线图", font1, brush1, new PointF(85, 30));//画图⽚的边框线g.DrawRectangle(new Pen(Color.Blue), 0, 0, image.Width - 1, image.Height - 1);Pen mypen = new Pen(brush, 1);Pen mypen2 = new Pen(Color.Red, 2);//绘制线条//绘制纵向线条int x = 60;for (int i = 0; i < 8; i++){g.DrawLine(mypen, x, 80, x, 340);x = x + 80;}Pen mypen1 = new Pen(Color.Blue, 3);x = 60;g.DrawLine(mypen1, x, 82, x, 340);//绘制横向线条int y = 106;for (int i = 0; i < 10; i++){g.DrawLine(mypen, 60, y, 620, y);y = y + 26;}// y = 106;g.DrawLine(mypen1, 60, y - 26, 620, y - 26);//x轴String[] n = { "第⼀期", "第⼆期", "第三期", "第四期", "上半年", "下半年", "全年统计" };x = 45;for (int i = 0; i < 7; i++){g.DrawString(n[i].ToString(), font, Brushes.Red, x, 348); //设置⽂字内容及输出位置x = x + 77;}//y轴String[] m = { "220⼈", " 200⼈", " 175⼈", "150⼈", " 125⼈", " 100⼈", " 75⼈", " 50⼈"," 25⼈"};y = 100;for (int i = 0; i < 9; i++){g.DrawString(m[i].ToString(), font, Brushes.Red, 10, y); //设置⽂字内容及输出位置y = y + 26;}int[] Count1 = new int[7];int[] Count2 = new int[7];SqlConnection Con = new SqlConnection("Server=(Local);Database=committeeTraining;Uid=sa;Pwd=eesoft"); Con.Open();string cmdtxt2 = "SELECT * FROM ##Count where Company='" + this.ddlTaget.SelectedItem.Text.Trim() + "'"; SqlDataAdapter da = new SqlDataAdapter(cmdtxt2, Con);DataSet ds = new DataSet();da.Fill(ds);//报名⼈数Count1[0] = Convert.ToInt32(ds.Tables[0].Rows[0]["count1"].ToString());Count1[1] = Convert.ToInt32(ds.Tables[0].Rows[0]["count3"].ToString());Count1[2] = Convert.ToInt32(ds.Tables[0].Rows[0]["count5"].ToString());Count1[3] = Convert.ToInt32(ds.Tables[0].Rows[0]["count7"].ToString());Count1[6] = Convert.ToInt32(ds.Tables[0].Rows[0]["count9"].ToString()); //全年Count1[4] = Count1[0] + Count1[1];Count1[5] = Count1[2] + Count1[3];Count2[0] = Convert.ToInt32(ds.Tables[0].Rows[0]["count2"].ToString());Count2[1] = Convert.ToInt32(ds.Tables[0].Rows[0]["count4"].ToString());Count2[2] = Convert.ToInt32(ds.Tables[0].Rows[0]["count6"].ToString());Count2[3] = Convert.ToInt32(ds.Tables[0].Rows[0]["count8"].ToString());Count2[6] = Convert.ToInt32(ds.Tables[0].Rows[0]["count10"].ToString()); //全年Count2[4] = Count2[0] + Count2[1];Count2[5] = Count2[2] + Count2[3];//显⽰折线效果Font font3 = new System.Drawing.Font("Arial", 10, FontStyle.Bold);SolidBrush mybrush = new SolidBrush(Color.Red);Point[] points1 = new Point[7];points1[0].X = 60; points1[0].Y = 340 - Count1[0]; //从106纵坐标开始, 到(0, 0)坐标时points1[1].X = 140; points1[1].Y = 340 - Count1[1];points1[2].X = 220; points1[2].Y = 340 - Count1[2];points1[3].X = 300; points1[3].Y = 340 - Count1[3];points1[4].X = 380; points1[4].Y = 340 - Count1[4];points1[5].X = 460; points1[5].Y = 340 - Count1[5];points1[6].X = 540; points1[6].Y = 340 - Count1[6];g.DrawLines(mypen2, points1); //绘制折线//绘制数字g.DrawString(Count1[0].ToString(), font3, Brushes.Red, 58, points1[0].Y - 20);g.DrawString(Count1[1].ToString(), font3, Brushes.Red, 138, points1[1].Y - 20);g.DrawString(Count1[2].ToString(), font3, Brushes.Red, 218, points1[2].Y - 20);g.DrawString(Count1[3].ToString(), font3, Brushes.Red, 298, points1[3].Y - 20);g.DrawString(Count1[4].ToString(), font3, Brushes.Red, 378, points1[4].Y - 20);g.DrawString(Count1[5].ToString(), font3, Brushes.Red, 458, points1[5].Y - 20);g.DrawString(Count1[6].ToString(), font3, Brushes.Red, 538, points1[6].Y - 20);Pen mypen3 = new Pen(Color.Green, 2);Point[] points2 = new Point[7];points2[0].X = 60; points2[0].Y = 340 - Count2[0];points2[1].X = 140; points2[1].Y = 340 - Count2[1];points2[2].X = 220; points2[2].Y = 340 - Count2[2];points2[3].X = 300; points2[3].Y = 340 - Count2[3];points2[4].X = 380; points2[4].Y = 340 - Count2[4];points2[5].X = 460; points2[5].Y = 340 - Count2[5];points2[6].X = 540; points2[6].Y = 340 - Count2[6];g.DrawLines(mypen3, points2); //绘制折线//绘制通过⼈数g.DrawString(Count2[0].ToString(), font3, Brushes.Green, 61, points2[0].Y - 15); g.DrawString(Count2[1].ToString(), font3, Brushes.Green, 131, points2[1].Y - 15); g.DrawString(Count2[2].ToString(), font3, Brushes.Green, 221, points2[2].Y - 15); g.DrawString(Count2[3].ToString(), font3, Brushes.Green, 301, points2[3].Y - 15);g.DrawString(Count2[4].ToString(), font3, Brushes.Green, 381, points2[4].Y - 15); g.DrawString(Count2[5].ToString(), font3, Brushes.Green, 461, points2[5].Y - 15);g.DrawString(Count2[6].ToString(), font3, Brushes.Green, 541, points2[6].Y - 15);//绘制标识g.DrawRectangle(new Pen(Brushes.Red), 180, 390, 250, 50); //绘制范围框g.FillRectangle(Brushes.Red, 270, 402, 20, 10); //绘制⼩矩形g.DrawString("报名⼈数", font2, Brushes.Red, 292, 400);g.FillRectangle(Brushes.Green, 270, 422, 20, 10);g.DrawString("通过⼈数", font2, Brushes.Green, 292, 420);System.IO.MemoryStream ms = new System.IO.MemoryStream();image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);Response.ClearContent();Response.ContentType = "image/Jpeg";Response.BinaryWrite(ms.ToArray());}finally{g.Dispose();image.Dispose();}}三. 扇形统计图的绘制效果图:扇形图完整代码:private void CreateImage(){//把连接字串指定为⼀个常量SqlConnection Con = new SqlConnection("Server=(Local);Database=committeeTraining;Uid=sa;Pwd=**");Con.Open();string cmdtxt = selectString; // "select * from ##Count"; ////SqlCommand Com = new SqlCommand(cmdtxt, Con);DataSet ds = new DataSet();SqlDataAdapter Da = new SqlDataAdapter(cmdtxt, Con);Da.Fill(ds);Con.Close();float Total = 0.0f, Tmp;//转换成单精度。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
void CBihetuxingView::OnDraw(CDC* pDC)
{
CBihetuxingDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CPen Pen; CPen *OldPen;
Pen.CreatePen(PS_SOLID,2,RGB(255,255,0));
CBrush Brush;CBrush *OldBrush;
Brush.CreateHatchBrush(4,RGB(0,200,200));//填充部分的内容,HS_BDIAGONALHS_BDIAGONAL 向下阴影(从左到右)在45度
//HS_CROSS 水平和垂直跨阴影线//在45度的HS_DIAGCROSS 跨阴影线//HS_FDIAGONAL 向上阴影(从左到右)在45度
//HS_HORIZONTAL 级别的阴影//HS_VERTICAL 垂直阴影//CBrush::CreateHatchBrush初始化具有指定的阴影的模式和颜色的画笔。
OldPen= pDC->SelectObject(&Pen);
OldBrush=pDC->SelectObject(&Brush);
pDC->RoundRect(100,100,300,300,30,60);//矩形nLeftRect:指定矩形左上角的X坐标。
//nTopRect:指定矩形左上角的Y坐标。
//nRightRect:指定矩形右下角的X坐标。
//nbottomRect:指定矩形右下角的Y坐标。
//nWidth:指定用来画圆角的椭圆的宽。
//nHeight:指定用来画圆角的椭圆的高。
//BOOL RoundRect(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int nWidth, int nHeight);
pDC->SetBkColor(RGB(255,255,0));
pDC->SetBkMode(OPAQUE);
pDC->Ellipse(300,100,500,200);//椭圆
pDC->Pie(300,100,600,400,300,400,600,400);//扇形
pDC->SelectObject(OldPen);
pDC->SelectObject(OldBrush);。