欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C語言實(shí)現(xiàn)繪制南丁格爾玫瑰圖的示例代碼

 更新時(shí)間:2024年03月05日 11:56:19   作者:老花眼貓  
玫瑰圖中有一種不等半徑的統(tǒng)計(jì)圖稱為南丁格爾玫瑰圖,網(wǎng)上很熱門,是一很有藝術(shù)感的漂亮的統(tǒng)計(jì)圖,下面我們就來看看如何使用C語言繪制它吧

C語言繪制南丁格爾玫瑰圖

常用的統(tǒng)計(jì)圖有條形圖、柱形圖、折線圖、曲線圖、餅圖、環(huán)形圖、扇形圖。

前幾類圖比較容易繪制,餅圖環(huán)形圖繪制較難。

玫瑰圖的繪制也較難,有一種不等半徑的統(tǒng)計(jì)圖稱為南丁格爾玫瑰圖,網(wǎng)上很熱門。是一很有藝術(shù)感的漂亮的統(tǒng)計(jì)圖。

今就提供此種玫瑰圖的繪制方法供參考。

本方法采用C語言的最基本功能:

( 1) 繪圖功能畫線,畫圓,畫長方形。

(2) 界面美工設(shè)計(jì),界面文字打印輸出。

代碼中有詳細(xì)的注釋,通俗易懂,一看就會(huì)。

效果圖

實(shí)現(xiàn)代碼

下面是繪制南丁格爾玫瑰圖的代碼:

//變量: 可設(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ù)
Int cr,cg,cb ;      //設(shè)置色彩 set Color (a,r,g,b)

//*************************       
PieGraph2 (){  
//南丁格爾玫瑰圖(不等半徑扇形圖)
      cs.ClearDraw (0,src);   //清屏
      clearOutput();
      selectStyle () ; //圖例樣式選項(xiàng)設(shè)置0
      cs.SetFillMode (1);//0不填色,1填色
      cs.SetStrokeWidth(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,230,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.SetTextSize (30);      //題標(biāo)
          cs.SetColor (255,0,0,250);
      cs.DrawText ("PieGraph ?",510,70) ;

          dx=360 ; dy=300 ;  
      for (i=1; i<=25 ; i++){   //底圖圓漸變色
               cg=i*10; cb=i*10 ;  L=cb-5 ;
          cs.SetColor(255,0,cg,cb);
       //   cs.DrawCircle(dx,dy,L);    //可設(shè)或不設(shè)
                      }  //底圖色

          cs.SetColor(255,250,250,250);
          cs.DrawCircle(dx,dy,185);    //底圖圓

 //繪制藝術(shù)圖表:不等半徑扇形圖
  p[1]=176;  p[2]=131;  p[3]=125;  p[4]=156; 
  p[5]=102;  p[6]=112;  p[7]=100;  p[8]=98;  //樣本值

     cs.SetFillMode (0);//0不填色,1填色
    for (n=0; n<=8 ; n++){   
       cs.SetColor(255,250,0,0);
       cs.DrawCircle(dx,dy,n*22+2);   }  //center圓標(biāo)線
       cs.DrawLine (dx-190,dy,dx+190,dy) ;
       cs.DrawLine (dx,dy-190,dx,dy+190) ;  //十字線

       k[0]=-180;   //180=12點(diǎn)鐘方向, 0=3 點(diǎn)鐘方向
       k[1]=k[0]+p[1]*72/100 ;
       k[2]=k[1]+p[2]*72/100 ;
       k[3]=k[2]+p[3]*72/100 ;
       k[4]=k[3]+p[4]*72/100 ;
       k[5]=k[4]+p[5]*72/100 ;
       k[6]=k[5]+p[6]*72/100;
       k[7]=k[6]+p[7]*72/100 ;
       k[8]=k[7]+p[8]*72/100 ;
    
      cs.SetFillMode (1);//0不填色,1填色
      cs.SetStrokeWidth(2);
   for (n=1; n<=8 ; n++){   //data=8, draw Piegraph
            r=p[n]-10 ;    //半徑依樣本值大小
     for (i= k[n-1]+3; i<=k[n]-3; i++){  //+ - 3 色塊分隔線
       if (n==1) cs.SetColor(85,250,0,0);
       if (n==2) cs.SetColor(85,250,150,0);
       if (n==3) cs.SetColor(85,0,250,0);
       if (n==4) cs.SetColor(85,0,200,0);
       if (n==5) cs.SetColor(85,100,150,250);
       if (n==6) cs.SetColor(85,250,120,200);
       if (n==7) cs.SetColor(85,0,200,250);
       if (n==8) cs.SetColor(85,150,50,230);
                 a=pi/360*i ;     
           x0=(float)(r*cos (a))+dx ;     //r=radius
           y0=(float)(r*sin (a))+dy ;
           cs.DrawLine (dx,dy,x0,y0);     //draw out
      cs.DrawRect (90,n*40+20,165,n*40+50); //色標(biāo)

   //** print data as "28%"
          cs.SetTextStyle (0);
          cs.SetTextSize (18);
          s=intToString (p[n]);
           cs.DrawText (s, 50,40+n*40);   //標(biāo)樣本值
           pn=p[n]*10000/720 ;    //擴(kuò)大100
           pn=pn/100 ;      //保留2位小數(shù)
          ss1=doubleToString (pn)+"%" ;
       cs.SetColor(255,250,250,250);
           cs.DrawText (ss1,100,40+n*40);
       cs.SetColor(255,250,250,250);    //圖上標(biāo)( n% )
           ss2=intToString (p[n]) ;
           ma=pi/360*((k[n-1]+k[n])/2) ;
            x1=(float)((r-38)*cos (ma))+dx-20;     
            y1=(float)((r-38)*sin (ma))+dy ;
            cs.DrawText (ss2,x1,y1);     //
            cs.Update ();      }   }
 
 //打印統(tǒng)計(jì)圖題標(biāo) 
      cs.SetFillMode (1);//0不填色,1填色
      cs.SetTextSize (43);
      cs.SetTextStyle (1);
      cs.SetStrokeWidth(1);
           ss="統(tǒng)計(jì)圖  -  南丁格爾玫瑰圖" ;
      cs.SetColor(255,50,120,20);      //立體字
           cs.DrawText (ss,114,534);    //陰影
      cs.SetColor(255,0,250,0);
           cs.DrawText (ss,110,530);    //本字
      cs.SetFillMode (0);//0不填色,1填色
      cs.SetColor(255,250,150,0);
           cs.DrawText (ss,110,530);    //框線
       cs.Update ();
}//PieGraph2 ()


//**** END *****************

知識(shí)補(bǔ)充

除了上述的玫瑰圖,小編還為大家整理了C語言繪制普通玫瑰圖的方法,希望對(duì)大家有所幫助

示例代碼

//變量: 可設(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ù)
 
//*************************  

RoseChart10 (){      //玫瑰圖繪制方法
    cs.ClearDraw (0,src);   //清屏
      clearOutput();
      selectStyle () ; //圖例樣式選項(xiàng)設(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.SetStrokeWidth(0);    //雷達(dá)圖底線
              dx=360;  dy=280 ;     //center
      cs.SetFillMode (1);//0不填色,1填色

      cs.SetColor(255,80,20,250);  
            //此底色可采用漸變色
      cs.DrawCircle(dx,dy,215);     //圓心圖例底色
 int cr,cg,cb;      //* set color(a,r,g,b)
      for (i=1; i<=11 ; i++){  //可采用底圖圓漸變色
               cb=200-i*25 ;  
               L=cb+40 ;
          cs.SetColor(255,80,0,cb);
          cs.DrawCircle(dx,dy,L);       }  //底圖色
               cs.SetColor(255,80,0,40);
          cs.DrawCircle(dx,dy,15);     //圓心補(bǔ)色

          cs.SetTextStyle (1);
          cs.SetStrokeWidth(1);
          cs.SetColor(255,250,0,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.SetFillMode (0);//0不填色,1填色
        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.SetFillMode (1);//0不填色,1填色
         cs.SetColor(255,250,250,0);
         cs.DrawText(ss,x1-5,285);         }  

          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+120 ;       //標(biāo)字
          x1=(float)(225*cos(a))+dx-5 ;
          y1=(float)(-225*sin(a))+dy+5 ;  //逆時(shí)針
               ss=intToString (i+1) ;
          cs.DrawText (ss,x1,y1) ;              }  

   //draw 色標(biāo)
          cs.SetColor (255,220,200,250);
          cs.DrawRect (550,80,685,180);   //標(biāo)底
              cs.SetColor (255,250,0,0);
          cs.DrawRect (630,90,670,110);   //red 
          cs.DrawText ("Group A", 560,105) ;                 
              cs.SetColor (255,0,250,0);
          cs.DrawRect (630,120,670,140);   //green
          cs.DrawText ("Group B", 560,135) ;                 
              cs.SetColor (255,250,250,0);
          cs.DrawRect (630,150,670,170);   //yellow 
          cs.DrawText ("Group C", 560,165) ;                 

   
//***************************************
//6個(gè)數(shù)據(jù)的堆疊式  玫瑰圖繪制方法:
//input data :  分三組(Group)
//每組6個(gè)分值  ( 平均數(shù)、百分?jǐn)?shù)或定量的比值 )
int p1[6], p2[6], p3[6] ;
int L ;      //高度,長度

//演示的數(shù)據(jù)是杜撰的,不代表真實(shí)的平均數(shù)
        cs.SetStrokeWidth(2);    //雷達(dá)圖線
        cs.SetFillMode (1);//0不填色,1填色
  //Draw Group 1 *************
     p1[0]=70; p1[1]=85; p1[2]=68; p1[3]=94; 
     p1[4]=60; p1[5]=75; 
    for (n=0; n<=5 ; n++){ //data=6, n=0, 0度點(diǎn)起繪出
            r=p1[n]+120 ;    //半徑依數(shù)值大小
       for (i= n*120+20; i<=n*120+100; i++){  
              cs.SetColor(200,250,0,0);
              a=pi/360*i ;     
           x0=(float)(r*cos (a))+dx ;     //r=radius
           y0=(float)(-r*sin (a))+dy ;     //逆時(shí)針
           cs.DrawLine (dx,dy,x0,y0);     //draw out
      cs.DrawRect (80,n*25+52,120,n*25+74); //色標(biāo)
   //** print data as ......
          cs.SetTextStyle (0);
          cs.SetTextSize (18);
          cs.SetColor(255,0,0,250);
          s=intToString(n+1)+" >   "+intToString (p1[n]);
          cs.DrawText (s, 55,70+n*25);
               cs.Update ();     }   }

 //Draw Group 2 ************
     p2[0]=78; p2[1]=65; p2[2]=69; p2[3]=70; 
     p2[4]=80; p2[5]=95; 
    for (n=0; n<=5 ; n++){ //data=6, n=0, 0度點(diǎn)起繪出
            r=p2[n]+80 ;    //半徑依數(shù)值大小
       for (i= n*120+20; i<=n*120+100; i++){  
              cs.SetColor(200,0,250,0);
              a=pi/360*i ;     
           x0=(float)(r*cos (a))+dx ;     //r=radius
           y0=(float)(-r*sin (a))+dy ;     //逆時(shí)針
           cs.DrawLine (dx,dy,x0,y0);     //draw out
      cs.DrawRect (80,n*25+213,120,n*25+234); //色標(biāo)
   //** print data as ......
          cs.SetTextStyle (0);
          cs.SetTextSize (18);
          cs.SetColor(255,0,0,250);
          s=intToString(n+1)+" >   "+intToString (p2[n]);
          cs.DrawText (s, 55,230+n*25);
               cs.Update ();      }   }

//Draw Group 3  ************
     p3[0]=50;  p3[1]=75; p3[2]=88; p3[3]=85; 
     p3[4]=97;  p3[5]=70; 
     for (n=0; n<=5 ; n++){ //data=6, n=0, 0度點(diǎn)起繪出
            r=p3[n]+40 ;    //半徑依數(shù)值大小
       for (i= n*120+20; i<=n*120+100; i++){  
              cs.SetColor(150,250,250,0);
              a=pi/360*i ;     
           x0=(float)(r*cos (a))+dx ;     //r=radius
           y0=(float)(-r*sin (a))+dy ;     //逆時(shí)針
           cs.DrawLine (dx,dy,x0,y0);     //draw out
      cs.DrawRect (80,n*25+373,120,n*25+394); //色標(biāo)
   //** print data as ......
          cs.SetTextStyle (0);
          cs.SetTextSize (18);
          cs.SetColor(255,0,0,250);
          s=intToString(n+1)+" >   "+intToString (p3[n]);
          cs.DrawText (s, 55,390+n*25);
               cs.Update ();      }   }

       cs.SetFillMode (0);//0不填色,1填色
        cs.SetStrokeWidth(2);
        cs.SetColor(255,250,0,0);    //指標(biāo)定量線
        cs.DrawCircle(dx,dy,215);  
        cs.SetColor(255,0,250,0);    //指標(biāo)定量線
        cs.DrawCircle(dx,dy,180);  
        cs.SetColor(255,250,250,0);    //指標(biāo)定量線
        cs.DrawCircle(dx,dy,140);  

 
//draw title 打印題標(biāo)文字
      cs.SetFillMode (1);//0不填色,1填色
      cs.SetTextStyle (1);
      cs.SetStrokeWidth(1);
           cs.SetTextSize (26);
      cs.SetColor(255,0,0,250);   //圖標(biāo)或企業(yè)標(biāo)
      cs.DrawText ("Rose Chart ??",500,60) ;
      cs.SetTextSize (50);
         ss="統(tǒng)計(jì)圖  -  玫瑰圖" ;
      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 ();
}//RoseChart10 ()

效果如圖

到此這篇關(guān)于C語言實(shí)現(xiàn)繪制南丁格爾玫瑰圖的示例代碼的文章就介紹到這了,更多相關(guān)C語言玫瑰圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • C++ Boost Parameter超詳細(xì)講解

    C++ Boost Parameter超詳細(xì)講解

    Boost是為C++語言標(biāo)準(zhǔn)庫提供擴(kuò)展的一些C++程序庫的總稱。Boost庫是一個(gè)可移植、提供源代碼的C++庫,作為標(biāo)準(zhǔn)庫的后備,是C++標(biāo)準(zhǔn)化進(jìn)程的開發(fā)引擎之一,是為C++語言標(biāo)準(zhǔn)庫提供擴(kuò)展的一些C++程序庫的總稱
    2022-11-11
  • QT中線程池QThreadPool類概念和使用方法詳解

    QT中線程池QThreadPool類概念和使用方法詳解

    這篇文章主要為大家介紹了QT中線程池QThreadPool類概念和使用方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-09-09
  • C語言實(shí)現(xiàn)搶紅包程序代碼精簡版

    C語言實(shí)現(xiàn)搶紅包程序代碼精簡版

    這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)搶紅包程序代碼的精簡版,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-07-07
  • C++實(shí)現(xiàn)教職工管理系統(tǒng)課程設(shè)計(jì)

    C++實(shí)現(xiàn)教職工管理系統(tǒng)課程設(shè)計(jì)

    這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)教職工管理系統(tǒng)課程設(shè)計(jì),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • 深入理解C/C++中的寫時(shí)拷貝

    深入理解C/C++中的寫時(shí)拷貝

    這篇文章主要給大家介紹了C/C++中寫時(shí)拷貝的相關(guān)資料,所謂寫時(shí)拷貝也就是拖延版的深拷貝,下面文章中介紹的非常清楚,需要的朋友可以參考學(xué)習(xí),下面來一起看看吧。
    2017-03-03
  • C++類成員初始化的三種方式

    C++類成員初始化的三種方式

    如果靜態(tài)成員不滿足常量性,則不可以就地聲明,而且即使常量的靜態(tài)成員也只能是整型或者枚舉型才能就地初始化。而非靜態(tài)成員變量的初始化則必須在構(gòu)造函數(shù)中進(jìn)行。首先,先得了解一下C++支持哪幾種類成員初始化的方式,下面我們就來看看具體內(nèi)容吧
    2021-09-09
  • C語言學(xué)籍管理系統(tǒng)源代碼

    C語言學(xué)籍管理系統(tǒng)源代碼

    這篇文章主要為大家詳細(xì)介紹了C語言學(xué)籍管理系統(tǒng)源代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-03-03
  • C語言實(shí)現(xiàn)數(shù)獨(dú)輔助器(附源碼)

    C語言實(shí)現(xiàn)數(shù)獨(dú)輔助器(附源碼)

    數(shù)獨(dú)是源自瑞士的一種數(shù)學(xué)游戲。是一種運(yùn)用紙、筆進(jìn)行演算的邏輯游戲。本文將利用C語言制作一個(gè)數(shù)獨(dú)輔助器,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-01-01
  • 一文掌握C++?中使用變量從定義到實(shí)踐

    一文掌握C++?中使用變量從定義到實(shí)踐

    變量是用于存儲(chǔ)數(shù)據(jù)值的容器,在?C++?中,有不同類型的變量(使用不同的關(guān)鍵字定義),這篇文章給大家介紹C++?中使用變量從定義到實(shí)踐記錄,感興趣的朋友跟隨小編一起看看吧
    2024-03-03
  • C語言數(shù)據(jù)結(jié)構(gòu)深入探索順序表

    C語言數(shù)據(jù)結(jié)構(gòu)深入探索順序表

    順序表,全名順序存儲(chǔ)結(jié)構(gòu),是線性表的一種,線性表用于存儲(chǔ)邏輯關(guān)系為“一對(duì)一”的數(shù)據(jù),順序表自然也不例外,不僅如此,順序表對(duì)數(shù)據(jù)的物理存儲(chǔ)結(jié)構(gòu)也有要求,跟隨下文來具體了解吧
    2022-03-03

最新評(píng)論