?? 繪制餅圖.c
字號:
#include "math.h"
#include "graphics.h"
#define PI 3.141593
main()
{
char s[30];
float values[4]={19,26,33,22};
char *categories[10]={"1","2","3","4","5","6","7","8","9","10"};
char *name[4]={"IBM","HP","COMPAQ","DELL"};
double x,y,bega,enda,midangle;
float total=0;
int radius=140,begangle=0,endangle;
int i,graphdriver,graphmode;
graphdriver=DETECT;
initgraph(&graphdriver,&graphmode,""); cleardevice();
setviewport(10,10,639,479,1);
setcolor(GREEN); rectangle(20,20,600,460); rectangle(530,40,590,115);
for (i=0;i<4;i++) total+=values[i];
for (i=0;i<4;i++)
{ endangle=360*values[i]/total+begangle;
bega=begangle*PI/180; enda=endangle*PI/180; midangle=(bega+enda)/2;
x=300+cos(midangle)*radius*1.5; y=240-sin(midangle)*radius*1.2;
sprintf(s,"%3.2f%",values[i]/total*100);
setcolor(WHITE);
setfillstyle(1,i+2); /* 設置填充模式 用實填充色i+2填充 */
pieslice(300,240,begangle,endangle+2,radius); /* 畫扇型并填充 */
outtextxy(x,y,s);
outtextxy(x,y-20,name[i]);
rectangle(540,55+12*i,560,60+12*i);
floodfill(550,57+12*i,WHITE);
outtextxy(565,55+12*i,categories[i]);
begangle=endangle;
}
getch();
closegraph();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -