立体统计图表绘制方法(凸显式环图)

立体统计图表绘制方法(凸显式环图)
记得我学统计学的时候,那些统计图表大都是平面的框框图,很呆板,就只是表现出统计的意义就好了。在网络科技发展进步的当下,原来一些传统的统计图表都有了进一步的创新。在统计图的形式和艺术表现力的美工方面都有了长足的进步。以前企业的PPT都依赖微软的各应用软件来制作图表,现时企业的PPT展示的图表应用不再满足于Excle,Word等的图表绘制方法,进而使用一些第三方应用软件来制作新颖漂亮的图表。由此而有许多图表制作的应用软件面市。这些图表很吸引眼球,我对此也很感兴趣,故试着写了一些各种式样图表的绘制方法,供有同好的同行参考和评论。如果自己在做PPT时加入自己设计制作的图表,我相信这会使人有耳目一新的感觉,还会得到大家的青睐。这会使你感到很有成就感。我就是这样做的。

新样式的统计图有复合式,堆叠式,展开式等等,不一而足。在美工艺术方面有许多独到新颖的样式,给人一个赏心悦目的感受。

今在此提供一种新颖漂亮的立体形式的统计图的绘制方法供参考。
分离式的立体图形绘制较难,再介绍一种凸显形式的立体环图。
凸显形式的立体图就是绘制立体的图块,以立体图块的体积来表现统计意义的占比分析,凸显主要的样本值。
本方法采用C语言的最基本功能:绘图功能画线,画圆,画矩形。
代码中有详细的注释,通俗易懂,一看就会。


下面是绘制艺术统计图表的代码:
//变量: 可设置成全局变量或私有变量
Canvas cs ;     //画布,绘制图表载体
float pi=3.1415926535 ;
float a ;            //三角函数 sin (a), cos (a), 
float r ;             //圆半径 radius
int i, j, n ;
float x0,y0,x1,y1,x2,y2 ;  //作图
float dx1,dy1,dx,dy ;             //中心坐标
string ss, ss1, ss2,ss3 ;         //打印文字
 int p[16] ;        //set data   or  input  data
 int  p1[16],  p2[16], p3[16] ;    //data
 double pn ;   //显示数据,计算
 int ca, cr, cg, cb ;     //设置颜色 setColor (a,r,g,b)  
 int ppn ;   //计算
 int tb ;      //set tab, print 
 int k0, k1 ;    //圆720线 起终点

//*************************  


ArtGraphics5 (){  //艺术统计图立体环图(体积式)
//体积以样本值大小定高度
      cs.ClearDraw (0,src);   //清屏
      clearOutput();
      selectStyle () ; //图例样式选项设置
      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,220,250,250);
      cs.DrawRect (20,20,700,580);   //back 
      cs.SetFillMode (0);//0不填色,1填色
         cs.SetColor (255,0,0,250);
      cs.DrawRect (20,20,700,580);   //back 
      cs.DrawRect (26,25,694,575);   //back 
 
  //艺术统计图样例: 图例 (立体环图, 体积凸显)
     cs.SetFillMode (1);//0不填色,1填色
            dx=360;  dy=260 ;   //center
         cs.SetColor (255,250,200,230);
      cs.DrawRect (50,80,150,280);   //样本值标底
      cs.DrawRect (555,80,665,280);   //样本值标底
          cs.SetStrokeWidth(1);    //线
          cs.SetTextStyle (0);  //1 粗体字
          cs.SetTextSize (24);
          cs.SetColor(255,0,0,250);
        cs.DrawText ("Group ",65,110);
           cs.SetTextSize (20);
        cs.DrawText (" A",55,140);
        cs.DrawText (" B",55,170);
        cs.DrawText (" C",55,200);
        cs.DrawText (" D",55,230);
        cs.DrawText (" E",55,260);

 //图例样本值:input data   
   p1[1]=4920; p1[2]=3000; p1[3]=1920; p1[4]=1560;  
   p1[5]=600;        //部门 12000
        k[0]=80;     //k=180,12点钟方向为0位
                            //k=0, 3点钟方向为0位
        k[1]=k[0]+p1[1]*72/1200 ;   //样本值合计12000
        k[2]=k[1]+p1[2]*72/1200 ;   //转换成整圆720线
        k[3]=k[2]+p1[3]*72/1200 ;
        k[4]=k[3]+p1[4]*72/1200 ;         
        k[5]=k[4]+p1[5]*72/1200 ;
 
 //绘制立体环图:
           cs.SetStrokeWidth(2);    //线
           dx=360;  dy=273 ;   r=160 ;  //center,  radius
        cs.SetColor(255,200,200,250);  
        cs.DrawCircle (dx+11, dy, 175);      //圆底色
 

cfb62aa433234b29aed705c85980edae.png 

45960804690b4c11b0c6e236f96b5091.png

 

//先绘制上面的第1块
           kn=p1[1]/200 ;
     for (t=1; t<=kn ; t++){   //底16线
      for (i= k[0]; i<=k[1] ; i++){  
              dx=360-3 ;  dy=265-t*2 ;   r=160 ;
             a=pi/360*i ;   
       cs.SetColor(255,200,50,130);
            x0=(float)(r*cos (a))+dx ;     //r=radius
            y0=(float)(- r*sin (a))+dy ;     //逆时针
            x1=(float)((r-120)*cos (a))+dx ;     //r=radius
            y1=(float)(- (r-120)*sin (a))+dy ;     //逆时针
        cs.DrawLine (x1,y1, x0,y0); 
            cs.SetColor(255,150,20,60);  //圆弧线
          cs.DrawCircle (x1,y1,1.5);    } 
              cs.Update ();      } //立体底色
 
     for (i= k[0]; i<=k[1] ; i++){  //绘制面上色
             dx=360-3 ;  dy=265-kn*2 ;
             a=pi/360*i ;   
         cs.SetColor(255,250,0,0);
            x0=(float)(r*cos (a))+dx ;     //r=radius
            y0=(float)(- r*sin (a))+dy ;     //逆时针
            x1=(float)((r-120)*cos (a))+dx ;     //r=radius
            y1=(float)(- (r-120)*sin (a))+dy ;     //逆时针
          cs.DrawLine (x1,y1, x0,y0);       
              cs.SetColor(255,250,210,200);  //圆弧线
          cs.DrawCircle (x0,y0,1.5);       
          cs.DrawCircle (x1,y1,1.5);      } //面上色
            a=pi/360*k[0] ;     
            x2=(float)(r*cos (a))+dx ;     //r=radius
            y2=(float)(- r*sin (a))+dy ;     //逆时针
            a=pi/360*k[0] ;     
            x3=(float)((r-120)*cos (a))+dx ;     //r=radius
            y3=(float)(- (r-120)*sin (a))+dy ;     //逆时针
         cs.DrawLine (x1,y1, x0,y0);      //分隔线
         cs.DrawLine (x3,y3, x2,y2);      //加分隔 

        cs.SetColor(255,250,0,0);   //色标字和%
    cs.DrawRect (80,1*30+90 ,140,1*30+115); //n=1
    cs.DrawRect (560,1*30+90 ,660,1*30+115); //n=1
            cs.SetColor(255,250,250,250);   
             pn=p1[1]*10 ;     //保留1位小数
             pn=pn/1200 ; 
           ss1=doubleToString (pn)+"%" ;
           ss2=intToString (p1[1]) ;
        cs.DrawText(ss2, 88,1*30+110);   //标样本值
            ma=pi/360*((k[0]+k[1])/2) ;
            x1=(float)((r-45)*cos (ma))+dx ;     
            y1=(float)(-(r-45)*sin (ma))+dy ;
         cs.DrawText (ss1,x1-20,y1+5);     //标%
        cs.Update () ; 
      sleep (1000) ;   //延迟1秒
     // return ;

 

b492a49a1ae048da87587b6ed5d78fa5.png 

//再绘制上面的第2块
          kn=p1[2]/200 ;
      for (t=1; t<=kn ; t++){   //底16线
      for (i= k[1]; i<=k[2]+1 ; i++){  
              dx=360-6 ;  dy=285-t*2 ;
           a=pi/360*i ;   
       cs.SetColor(255,180,90,0);
            x0=(float)(r*cos (a))+dx ;     //r=radius
            y0=(float)(- r*sin (a))+dy ;     //逆时针
            x1=(float)((r-120)*cos (a))+dx ;     //r=radius
            y1=(float)(- (r-120)*sin (a))+dy ;     //逆时针
       cs.DrawLine (x1,y1, x0,y0);     }  
             cs.Update ();     } //立体底色
 
     for (i= k[1]; i<=k[2]+1 ; i++){  //绘制面上色
             dx=360-6 ;  dy=285-kn*2 ;
             a=pi/360*i ;   
         cs.SetColor(255,250,150,0);
            x0=(float)(r*cos (a))+dx ;     //r=radius
            y0=(float)(- r*sin (a))+dy ;     //逆时针
            x1=(float)((r-120)*cos (a))+dx ;     //r=radius
            y1=(float)(- (r-120)*sin (a))+dy ;     //逆时针
        cs.DrawLine (x1,y1, x0,y0);       
            cs.SetColor(255,250,220,0);  //圆弧线
        cs.DrawCircle (x0,y0,1.5);      
        cs.DrawCircle (x1,y1,1.5);         }//面上色
            a=pi/360*k[1] ;     
            x2=(float)(r*cos (a))+dx ;     //r=radius
            y2=(float)(- r*sin (a))+dy ;     //逆时针
           a=pi/360*k[1] ;     
            x3=(float)((r-120)*cos (a))+dx ;     //r=radius
            y3=(float)(- (r-120)*sin (a))+dy ;     //逆时针
         cs.DrawLine (x1,y1, x0,y0);      //分隔线
         cs.DrawLine (x3,y3, x2,y2);      //加分隔线
 
        cs.SetColor(255,250,200,0);   //色标字和%
     cs.DrawRect (80,2*30+90 ,140,2*30+115); //n
     cs.DrawRect (560,2*30+90 ,660,2*30+115); //n
             cs.SetColor(255,250,250,250);   
             pn=p1[2]*10 ;     //保留1位小数
             pn=pn/1200 ; 
           ss1=doubleToString (pn)+"%" ;
           ss2=intToString (p1[2]) ;
        cs.DrawText(ss2, 88,2*30+110);   //标样本值
            ma=pi/360*((k[1]+k[2])/2) ;
            x1=(float)((r-45)*cos (ma))+dx ;     
            y1=(float)(-(r-45)*sin (ma))+dy ;
          cs.DrawText (ss1,x1-27,y1+5);     //标%
      cs.Update () ; 
      sleep (1000) ;   //延迟1秒
    // return ;

6cb69a04634f4766878f713b545f4f8e.png 

//再绘制上面的第5块
          kn=p1[5]/200 ;
     for (t=1; t<=kn ; t++){   //底16线
      for (i= k[4]; i<=k[5] ; i++){  
              dx=360+4 ;  dy=262-t*2 ;
           a=pi/360*i ;   // a/2 绘出的是半圆
       cs.SetColor(255,0,120,200);
            x0=(float)(r*cos (a))+dx ;     //r=radius
            y0=(float)(- r*sin (a))+dy ;     //逆时针
            x1=(float)((r-120)*cos (a))+dx ;     //r=radius
            y1=(float)(- (r-120)*sin (a))+dy ;     //逆时针
       cs.DrawLine (x1,y1, x0,y0);     }    } //立体底色

     for (i= k[4]; i<=k[5] ; i++){  //绘制面上色
             dx=360+4 ;  dy=262-kn*2 ;
             a=pi/360*i ;   
         cs.SetColor(255,0,200,250);
            x0=(float)(r*cos (a))+dx ;     //r=radius
            y0=(float)(- r*sin (a))+dy ;     //逆时针
            x1=(float)((r-120)*cos (a))+dx ;     //r=radius
            y1=(float)(- (r-120)*sin (a))+dy ;     //逆时针
        cs.DrawLine (x1,y1, x0,y0);       
            cs.SetColor(185,200,250,250);  //圆弧线
        cs.DrawCircle (x0,y0,1.5);      
        cs.DrawCircle (x1,y1,1.5);         } //面上色
            a=pi/360*k[4] ;     
            x2=(float)(r*cos (a))+dx ;     //r=radius
            y2=(float)(- r*sin (a))+dy ;     //逆时针
            a=pi/360*k[4] ;     
            x3=(float)((r-120)*cos (a))+dx ;     //r=radius
            y3=(float)(- (r-120)*sin (a))+dy ;     //逆时针
              cs.SetColor(205,200,250,250);  
         cs.DrawLine (x1,y1, x0,y0);      //分隔线
         cs.DrawLine (x3,y3, x2,y2);      //加分隔线

        cs.SetColor(255,0,200,250);   //色标字和%
    cs.DrawRect (80,5*30+90 ,140,5*30+115); //n
    cs.DrawRect (560,5*30+90 ,660,5*30+115); //n
             cs.SetColor(255,250,250,250);   
             pn=p1[5]*10 ;     //保留1位小数
             pn=pn/1200 ; 
           ss1=doubleToString (pn)+"%" ;
           ss2=intToString (p1[5]) ;
            tb=0 ;
          if (p1[5]<1000) tb=11 ;   //右齐
     cs.DrawText(ss2, 88+tb,5*30+110);   //标样本值
            ma=pi/360*((k[4]+k[5])/2) ;
            x1=(float)((r-45)*cos (ma))+dx ;     
            y1=(float)(-(r-45)*sin (ma))+dy ;
          cs.DrawText (ss1,x1-20,y1+8);     //标%
      cs.Update () ; 
      sleep (1000) ;   //延迟1秒
   //return ;

e1bbf137ad614b9398600646bfbb7e39.png 

//绘制第4块
           kn=p1[4]/200 ;
     for (t=1; t<=kn ; t++){   //底16线
        for (i= k[3]; i<=k[4] ; i++){  
              dx=360+6 ;  dy=277-t*2 ;
           a=pi/360*i ;   // a/2 绘出的是半圆
              cs.SetColor(255,140,40,220);
            x0=(float)(r*cos (a))+dx ;     //r=radius
            y0=(float)(- r*sin (a))+dy ;     //逆时针
            x1=(float)((r-120)*cos (a))+dx ;     //r=radius
            y1=(float)(- (r-120)*sin (a))+dy ;     //逆时针
       cs.DrawLine (x1,y1, x0,y0);     }    } //立体底色

     for (i= k[3]; i<=k[4] ; i++){  //绘制面上色
             dx=360+6 ;  dy=277-kn*2 ;
             a=pi/360*i ;   
         cs.SetColor(255,240,130,240);
            x0=(float)(r*cos (a))+dx ;     //r=radius
            y0=(float)(- r*sin (a))+dy ;     //逆时针
            x1=(float)((r-120)*cos (a))+dx ;     //r=radius
            y1=(float)(- (r-120)*sin (a))+dy ;     //逆时针
        cs.DrawLine (x1,y1, x0,y0);       
            cs.SetColor(255,250,220,250);  //圆弧线
        cs.DrawCircle (x0,y0,1.5);      
        cs.DrawCircle (x1,y1,1.5);         } //面上色
            a=pi/360*k[3] ;     
            x2=(float)(r*cos (a))+dx ;     //r=radius
            y2=(float)(- r*sin (a))+dy ;     //逆时针
            a=pi/360*k[3] ;     
            x3=(float)((r-120)*cos (a))+dx ;     //r=radius
            y3=(float)(- (r-120)*sin (a))+dy ;     //逆时针
         cs.DrawLine (x1,y1, x0,y0);      //分隔线
         cs.DrawLine (x3,y3, x2,y2);      //加分隔线

        cs.SetColor(255,240,130,240);   //色标字和%
    cs.DrawRect (80,4*30+90 ,140,4*30+115); //n
    cs.DrawRect (560,4*30+90 ,660,4*30+115); //n
             cs.SetColor(255,250,250,250);   
             pn=p1[4]*10 ;     //保留1位小数
             pn=pn/1200 ; 
           ss1=doubleToString (pn)+"%" ;
           ss2=intToString (p1[4]) ;
      cs.DrawText(ss2, 88,4*30+110);   //标样本值
            ma=pi/360*((k[3]+k[4])/2) ;
            x1=(float)((r-45)*cos (ma))+dx ;     
            y1=(float)(-(r-45)*sin (ma))+dy ;
          cs.DrawText (ss1,x1-27,y1+5);     //标%
      cs.Update () ; 
      sleep (1000) ;   //延迟1秒
  // return ;

b0be9f0ce8eb4e98a979bd9e75d8fd0e.png
  
//最后绘制下面的第3块 > 完成
           kn=p1[3]/200 ;
      for (t=1; t<=kn ; t++){   //底16线
      for (i= k[2]; i<=k[3] ; i++){  
              dx=360+3;  dy=284-t*2 ;
           a=pi/360*i ;   // a/2 绘出的是半圆
       cs.SetColor(255,0,120,0);
            x0=(float)(r*cos (a))+dx ;     //r=radius
            y0=(float)(- r*sin (a))+dy ;     //逆时针
            x1=(float)((r-120)*cos (a))+dx ;     //r=radius
            y1=(float)(- (r-120)*sin (a))+dy ;     //逆时针
       cs.DrawLine (x1,y1, x0,y0);     }    } //立体底色

 

     for (i= k[2]; i<=k[3] ; i++){  //绘制面上色
             dx=360+3 ;  dy=284-kn*2 ;
             a=pi/360*i ;   
         cs.SetColor(255,0,210,0);
            x0=(float)(r*cos (a))+dx ;     //r=radius
            y0=(float)(- r*sin (a))+dy ;     //逆时针
            x1=(float)((r-120)*cos (a))+dx ;     //r=radius
            y1=(float)(- (r-120)*sin (a))+dy ;     //逆时针
        cs.DrawLine (x1,y1, x0,y0);       
            cs.SetColor(255,0,250,0);  //圆弧线
        cs.DrawCircle (x0,y0,1.5);      
        cs.DrawCircle (x1,y1,1.5);         } //面上色
            a=pi/360*k[2] ;     
            x2=(float)(r*cos (a))+dx ;     //r=radius
            y2=(float)(- r*sin (a))+dy ;     //逆时针
            a=pi/360*k[2] ;     
            x3=(float)((r-120)*cos (a))+dx ;     //r=radius
            y3=(float)(- (r-120)*sin (a))+dy ;     //逆时针
         cs.DrawLine (x1,y1, x0,y0);      //分隔线
         cs.DrawLine (x3,y3, x2,y2);      //加分隔线

        cs.SetColor(255,0,230,0);   //色标字和%
    cs.DrawRect (80,3*30+90 ,140,3*30+115); //n
    cs.DrawRect (560,3*30+90 ,660,3*30+115); //n
             cs.SetColor(255,250,250,250);   
             pn=p1[3]*10 ;     //保留1位小数
             pn=pn/1200 ; 
           ss1=doubleToString (pn)+"%" ;
           ss2=intToString (p1[3]) ;
     cs.DrawText(ss2, 88,3*30+110);   //标样本值
            ma=pi/360*((k[2]+k[3])/2) ;
            x1=(float)((r-45)*cos (ma))+dx ;     
            y1=(float)(-(r-45)*sin (ma))+dy ;
          cs.DrawText (ss1,x1-25,y1+5);     //标%
      cs.Update () ; 

           cs.SetColor(255,0,0,250);
        cs.DrawText ("年龄段分析",560,110);
           cs.SetColor(255,250,250,250);
        cs.DrawText ("20-30岁",570,140);
        cs.DrawText ("30-40岁",570,170);
        cs.DrawText ("40-50岁",570,200);
        cs.DrawText ("50-60岁",570,230);
        cs.DrawText ("60岁以上",570,260);
      sleep (1000) ;   //延迟1秒
          
//题标:  艺术立体字制作
        cs.SetFillMode (1);//0不填色,1填色
        cs.SetTextStyle (1);
        cs.SetStrokeWidth(1);
        cs.SetTextSize (28);
        cs.SetColor(255,0,0,250);      
      cs.DrawText ("Art Graphics 📊",480,60) ;
      cs.SetTextSize (41);
         ss="艺术统计图:立体环图(凸显)" ;
      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 ();
}//ArtGraphics5 ()

 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值