C語言繪制雷達(dá)圖的示例代碼
統(tǒng)計圖雷達(dá)圖繪制方法
常用的統(tǒng)計圖有條形圖、柱形圖、折線圖、曲線圖、餅圖、環(huán)形圖、扇形圖。
前幾類圖比較容易繪制,餅圖環(huán)形圖繪制較難。
還有一種雷達(dá)圖的繪制也較難,今提供雷達(dá)圖的繪制方法供參考。
本方法采用C語言的最基本功能:
( 1) 繪圖功能畫線,畫圓,畫長方形。
(2) 界面美工設(shè)計,界面文字打印輸出。
代碼中有詳細(xì)的注釋,通俗易懂,一看就會。
效果圖
實現(xiàn)代碼
下面是繪制雷達(dá)圖的代碼:
//變量: 可設(shè)置成全局變量或私有變量 Canvas cs ; //畫布,繪制圖表載體 float pi=3.1415926535 ; float a ; //三角函數(shù) sin (a), cos (a), float r ; //圓半徑 radius int i, j, n ; float x0,y0,x1,y1 ; //作圖坐標(biāo) float dx,dy ; //中心坐標(biāo) string ss, ss1, ss2 ; //打印文字 int p[6] ; //set data or input data double pn ; //顯示數(shù)據(jù)
3組樣例逐步繪出:
RadarChart (){ //8. 雷達(dá)圖繪制方法 cs.ClearDraw (0,src); //清屏 clearOutput(); selectStyle () ; //圖例樣式選項設(shè)置 cs.SetFillMode (1);//0不填色,1填色 cs.SetColor (255,250,250,250); cs.DrawRect (0,4,720,600); //back board cs.SetColor (255,140,140,140); cs.DrawRect (24,24,706,586); //back cs.SetColor (255,240,240,250); cs.DrawRect (20,20,700,580); //back cs.SetFillMode (0);//0不填色,1填色 cs.SetColor (255,0,0,240); cs.DrawRect (20,20,700,580); //框線 cs.DrawRect (24,24,696,576); //框線 cs.SetFillMode (1);//0不填色,1填色 cs.SetStrokeWidth(0); //雷達(dá)圖底線 dx=360; dy=280 ; //center int color ; for (i=1; i<=11 ; i++){ //底圖圓漸變色 color=200-i*25 ; L=color+40 ; cs.SetColor(255,80,0,color); cs.DrawCircle(dx,dy,L); } //底圖色 cs.SetColor(255,80,0,40); cs.DrawCircle(dx,dy,20); //圓心 cs.SetFillMode (0);//0不填色,1填色 cs.SetColor(255,250,0,0); cs.SetTextStyle (0); cs.SetTextSize (16); for (i=1; i<=10 ; i++){ //畫標(biāo)線圓和標(biāo)值 a=pi/360*i ; x0=(float)(200*cos (a))+dx ; y0=(float)(200*sin (a))+dy ; cs.SetColor(255,250,250,250); cs.DrawCircle(dx,dy,i*20); x1=(float)(i*20*cos (a))+dx ; y1=(float)(i*20*sin (a))+dy ; ss=intToString (i); cs.DrawText(ss,x1-8,275); } cs.SetFillMode (1);//0不填色,1填色 cs.SetTextSize (18); cs.SetColor(255,250,0,0); for (i=0; i<=5 ; i++){ //標(biāo)線六角射線 a=pi/360*i*120 ; x0=(float)(220*cos(a))+dx ; y0=(float)(220*sin(a))+dy ; cs.DrawLine (x0,y0,dx,dy); a=pi/360*i*120 ; //標(biāo)字 x1=(float)(230*cos(a))+dx-5 ; y1=(float)(-230*sin(a))+dy+5 ; //逆時針 ss=intToString (i+1) ; cs.DrawText (ss,x1,y1) ; } cs.SetTextSize (22); cs.DrawText ("1. 語文",610,285) ; cs.DrawText ("2. 數(shù)學(xué)",610,310) ; cs.DrawText ("3. 外語",610,335) ; cs.DrawText ("4. 政治",610,360) ; cs.DrawText ("5. 理化",610,385) ; cs.DrawText ("6. 史地",610,415) ; //******************************** //雷達(dá)圖繪制方法: //input data : 分三組,每組6個分?jǐn)?shù)(或平均分?jǐn)?shù)) int p1[6], p2[6], p3[6] ; int L ; //高度,長度 //演示的數(shù)據(jù)是杜撰的,不代表真實的平均數(shù) cs.SetStrokeWidth(3); //雷達(dá)圖線 //Draw Group 1 ************* p1[0]=85; //0位,起點 p1[1]=85; p1[2]=68; p1[3]=94; p1[4]=60; p1[5]=75; p1[6]=88; cs.SetColor(255,250,0,250); //group 1 L=p1[1]*2 ; a=pi/360 ; x0=(float)(L*cos(a))+dx ; y0=(float)(-L*sin(a))+dy ; cs.DrawCircle(x0,y0,5); x2=x0; y2=y0; for (i=1; i<=5; i++){ //六角射線點 L=p1[i+1]*2 ; a=pi/360*i*120 ; x1=(float)(L*cos(a))+dx ; y1=(float)(-L*sin(a))+dy ; //逆時針 cs.DrawCircle(x1,y1,5); cs.DrawLine (x2,y2,x1,y1); //連線 x2=x1; y2=y1 ; } cs.DrawLine (x2,y2,x0,y0); //連線0點 cs.Update (); for (i=1; i<=6; i++){ //打印色標(biāo) ss=intToString (i)+" . "+intToString (p1[i]) ; cs.DrawText (ss, 60, i*20+60) ; } cs.DrawText ("Group 1 ", 50, 60) ; sleep (1000); //逐步展示 //Draw Group 2 ************ p2[0]=65 ; p2[1]=65; p2[2]=69; p2[3]=70; p2[4]=80; p2[5]=95; p2[6]=78; cs.SetColor(255,0,200,0); //group 2 L=(int)(p2[1]*2) ; a=pi/360 ; x0=(float)(L*cos(a))+dx ; y0=(float)(-L*sin(a))+dy ; cs.DrawCircle(x0,y0,5); x2=x0; y2=y0; for (i=1; i<=5; i++){ //六角射線點 L=(int)(p2[i+1]*2) ; a=pi/360*i*120 ; x1=(float)(L*cos(a))+dx ; y1=(float)(-L*sin(a))+dy ; //逆時針 cs.DrawCircle(x1,y1,5); cs.DrawLine (x2,y2,x1,y1); //連線 x2=x1; y2=y1 ; } cs.DrawLine (x2,y2,x0,y0); //連線回0點 cs.Update (); for (i=1; i<=6; i++){ //打印色標(biāo) ss=intToString (i)+" . "+intToString (p2[i]) ; cs.DrawText (ss, 60, i*20+210) ; } cs.DrawText ("Group 2 ", 50, 210) ; sleep (1000); //逐步展示 //Draw Group 3 ************ p3[0]=75 ; p3[1]=75; p3[2]=88; p3[3]=85; p3[4]=97; p3[5]=70; p3[6]=68; cs.SetColor(255,250,200,0); //group 3 L=p3[1]*2 ; a=pi/360 ; x0=(float)(L*cos(a))+dx ; y0=(float)(-L*sin(a))+dy ; cs.DrawCircle(x0,y0,5); x2=x0; y2=y0; for (i=1; i<=5; i++){ //六角射線點 L=p3[i+1]*2 ; a=pi/360*i*120 ; x1=(float)(L*cos(a))+dx ; y1=(float)(-L*sin(a))+dy ; //逆時針 cs.DrawCircle(x1,y1,5); cs.DrawLine (x2,y2,x1,y1); //連線 x2=x1; y2=y1 ; } cs.DrawLine (x2,y2,x0,y0); //連線回0點 for (i=1; i<=6; i++){ //打印色標(biāo) ss=intToString (i)+" . "+intToString (p3[i]) ; cs.DrawText (ss, 60, i*20+360) ; } cs.DrawText ("Group 3 ", 50, 360) ; //draw title cs.SetFillMode (1);//0不填色,1填色 cs.SetTextStyle (1); cs.SetStrokeWidth(1); cs.SetTextSize (26); cs.SetColor(255,0,0,250); cs.DrawText ("Radar Chart ??",500,60) ; cs.SetTextSize (50); ss="統(tǒng)計圖 - 雷達(dá)圖" ; cs.SetColor(255,50,120,20); //立體字 cs.DrawText (ss,164,534); //陰影 cs.SetColor(255,0,250,0); cs.DrawText (ss,160,530); //本字 cs.SetFillMode (0);//0不填色,1填色 cs.SetColor(255,250,150,0); cs.DrawText (ss,160,530); //框線 cs.Update (); }// RadarChart ()
到此這篇關(guān)于C語言繪制雷達(dá)圖的示例代碼的文章就介紹到這了,更多相關(guān)C語言雷達(dá)圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
CreateThread()與beginthread()的區(qū)別詳細(xì)解析
很多開發(fā)者不清楚這兩者之間的關(guān)系,他們隨意選一個函數(shù)來用,發(fā)現(xiàn)也沒有什么大問題,于是就忙于解決更為緊迫的任務(wù)去了。等到有一天忽然發(fā)現(xiàn)一個程序運行時間很長的時候會有細(xì)微的內(nèi)存泄露,開發(fā)者絕對不會想到是因為這兩套函數(shù)用混的結(jié)果2013-09-09openCV中meanshift算法查找目標(biāo)的實現(xiàn)
本文主要介紹了openCV中meanshift算法查找目標(biāo)的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-11-11