The use of C language to draw three-dimensional separation of the ring graph _C language _ script home

C language is used to draw the three-dimensional separate ring graph

Updated: Mar 20, 2024 11:27:01 By: Presbyopia Cat
This article mainly introduces the relevant knowledge of using C language to draw three-dimensional separated ring graph in detail, the example code in the article explains in detail, interested partners can follow Xiaobian together to learn

Method of drawing stereostatistical charts (separate ring chart)

I remember when I learned statistics, those statistical charts were mostly flat box charts, very stiff, just to show the significance of statistics. With the development and progress of network technology, some traditional statistical charts have been further innovated. There have been great advances in the form of statistical diagrams and in the art of artistic expression. In the past, the PPT of enterprises relied on Microsoft's various application software to make charts. Now, the chart application of PPT of enterprises is no longer satisfied with the chart drawing method of Excle, Word, etc., and then use some third-party application software to make novel and beautiful charts. As a result, many charting applications are available. These charts are very attractive, and I am very interested in them, so I try to write some drawing methods of various styles of charts, for the reference and comment of peers who have the same good. If I add the charts designed and produced by myself in the PPT, I believe it will make people have a fresh feeling and will be favored by everyone. This will make you feel a great sense of accomplishment. That's what I did.

The new style of statistical charts are composite, stacked, expanded, and so on. There are many unique and novel styles in the art of art, which give people a pleasant feeling.

This paper provides a new and beautiful drawing method of three-dimensional statistical graph for reference.

It is difficult to draw the separate type of three-dimensional graph, so the separate type of ring graph is introduced.

This method adopts the most basic functions of C language:

(1) Drawing function draw lines, draw circles, draw rectangles.

(2) Interface art design, interface text printout.

The code has detailed comments, easy to understand, a look will be.

Realization idea

Here is the code to chart art statistics:

// Variable: can be set to global variable or private variable Canvas cs; // Canvas, draw the chart carrier float pi=3.1415926535; float a ; // Trigonometric functions sin (a), cos (a), float r; // radius int i, j, n; float x0,y0,x1,y1,x2,y2 ; // Plot float dx1,dy1,dx,dy; // Center coordinate string ss, ss1, ss2,ss3; // Print the text int p[16]; //set data or input data int p1[16], p2[16], p3[16] ; //data double pn ; // Display data, calculate int ca, cr, cg, cb; // Set the color setColor (a,r,g,b) int ppn; // Calculate int tb; //set tab, print int k0, k1 ; 720 line up it / / / / round * * * * * * * * * * * * * * * * * * * * * * * * * ArtGraphics4 () {/ / art statistical figure 3 d circular diagram (separate) cs. ClearDraw (0, SRC); // Clear screen clearOutput(); selectStyle () ; // Legend style option set cs.SetFillMode (1); //0 does not fill the color, 1 fill the color 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 without color, 1 with color cs.SetColor (255,0,0,250); cs.DrawRect (20,20,700,580); DrawRect (26,25,694,575); //back cs.DrawRect (26,25,694,575); //back // Examples of art statistics: legend (separate stereoscopic ring) cs.SetFillMode (1); //0 uncolored, 1 colored dx=360; dy=260 ; //center cs.SetColor (255,250,200,230); cs.DrawRect (50,80,150,280); // Sample value base cs.SetStrokeWidth(1); // line cs.SetTextStyle (0); //1 Bold 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); // Legend sample value: input data p1[1]=2880; p1[2]=2400; p1[3]=2760; p1[4]=2040; p1[5]=1920; // Department 12000 k[0]=180; / / k = 0 180, 12 o 'clock direction / / k = 0, 3 o 'clock direction for 0 k [1] [0] = k + p1 [1] * 72/1200; // Total sample value 12000 k[2]=k[1]+p1[2]*72/1200; // Convert to full circle 720 line k[3]=k[2]+p1[3]*72/1200; k[4]=k[3]+p1[4]*72/1200 ; k[5]=k[4]+p1[5]*72/1200 ; // Draw a stereoscopic ring: cs.SetStrokeWidth(2); // line dx=360; dy=260 ; r=160 ; //center, radius cs.SetColor(255,200,200,250); cs.DrawCircle (dx+9, dy+7, 172); // Round background color

Effect drawing

Draw the first block above first

for (t=1; t<=8 ; t++){// Bottom 16 line for (i= k[0]; i<=k[1] ; i++){ dx=360-3 ; dy=245-t*2 ; r=160 ; a=pi/360*i ; Cs. SetColor (255200,80,160); x0=(float)(r*cos (a))+dx ; //r=radius y0=(float)(- r*sin (a))+dy ; // Counterclockwise x1=(float)((r-100)*cos (a))+dx; //r=radius y1=(float)(- (r-100)*sin (a))+dy ; // counterclockwise cs.DrawLine (x1,y1, x0,y0); }} // Solid base color for (i= k[0]; i<=k[1] ; i++){// Drawing surface color dx=360-3; dy=245-16 ; a=pi/360*i ; Cs. SetColor (255250120230); x0=(float)(r*cos (a))+dx ; //r=radius y0=(float)(- r*sin (a))+dy ; // Counterclockwise x1=(float)((r-100)*cos (a))+dx; //r=radius y1=(float)(- (r-100)*sin (a))+dy ; // counterclockwise cs.DrawLine (x1,y1, x0,y0); Cs. SetColor (255250210200); DrawCircle (x0,y0,1.5); cs.DrawCircle (x1,y1,1.5); } // face color a=pi/360*k[0]; x2=(float)(r*cos (a))+dx ; //r=radius y2=(float)(- r*sin (a))+dy ; // Counterclockwise a=pi/360*k[0]; x3=(float)((r-100)*cos (a))+dx ; //r=radius y3=(float)(- (r-100)*sin (a))+dy ; // Counterclockwise cs.SetColor(205,250,210,200); cs.DrawLine (x1,y1, x0,y0); DrawLine (x3,y3, x2,y2); // Drawline cs. drawline (x3,y3, x2,y2); // Add delimiter cs.SetColor(255,250,120,200); // Characters and % cs.DrawRect (80,1*30+90,140,1*30+115); //n=1 pn=p1[1]*10 ; // Reserve 1 decimal place pn=pn/1200; ss1=doubleToString (pn)+"%" ; ss2=intToString (p1[1]) ; Cs. SetColor (255250250, 0); cs.DrawText(ss2, 88,1*30+110); // Standard sample value cs.SetColor(255,250,250,250); // Plot superscript p1(n) 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-27,y1+5); // % cs.SetTextSize (24); Cs. SetColor (0, 255250); cs.DrawText ("Top declines ",170,120); cs.SetTextSize (20); cs.Update () ; sleep (1000) ; // Delay 1 second

The effect is as follows

Draw the fifth block above again

for (t=1; t<=8 ; t++){// Bottom 16 line for (i= k[4]; i<=k[5]+1 ; i++){ dx=360+10 ; dy=254-t*2 ; a=pi/360*i ; Cs. SetColor (255110,50,230); x0=(float)(r*cos (a))+dx ; //r=radius y0=(float)(- r*sin (a))+dy ; // Counterclockwise x1=(float)((r-100)*cos (a))+dx; //r=radius y1=(float)(- (r-100)*sin (a))+dy ; // counterclockwise cs.DrawLine (x1,y1, x0,y0); }} // Solid base color for (i= k[4]; i<=k[5]+1 ; i++){// Draw surface color dx=360+10; dy=254-16 ; a=pi/360*i ; Cs. SetColor (255180,80,250); x0=(float)(r*cos (a))+dx ; //r=radius y0=(float)(- r*sin (a))+dy ; // Counterclockwise x1=(float)((r-100)*cos (a))+dx; //r=radius y1=(float)(- (r-100)*sin (a))+dy ; // counterclockwise cs.DrawLine (x1,y1, x0,y0); Cs. SetColor (255220150250); DrawCircle (x0,y0,1.5); cs.DrawCircle (x1,y1,1.5); }// Face color a=pi/360*k[4]; x2=(float)(r*cos (a))+dx ; //r=radius y2=(float)(- r*sin (a))+dy ; // Counterclockwise a=pi/360*k[4]; x3=(float)((r-100)*cos (a))+dx ; //r=radius y3=(float)(- (r-100)*sin (a))+dy ; // Counterclockwise cs.SetColor(255,220,150,200); cs.DrawLine (x1,y1, x0,y0); DrawLine (x3,y3, x2,y2); // Drawline cs. drawline (x3,y3, x2,y2); // Add delimiter cs.SetColor(255,180,80,250); // Characters and % cs.DrawRect (80,5*30+90,140,5*30+115); //n=5 pn=p1[5]*10 ; // Reserve 1 decimal place pn=pn/1200; ss1=doubleToString (pn)+"%" ; ss2=intToString (p1[5]) ; Cs. SetColor (255250250, 0); cs.DrawText(ss2, 88,5*30+110); // Standard sample value cs.SetColor(255,250,250,250); // Plot superscript p1(n) 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-27,y1+5); // % cs.Update (); sleep (1000) ; // Delay 1 second

The effect is as follows

Draw the fourth block above again

for (t=1; t<=8 ; t++){// Bottom 16 line for (i= k[3]; i<=k[4] ; i++){ dx=360+15 ; dy=266-t*2 ; a=pi/360*i ; // a/2 draws a semicircle cs.SetColor(255,0,120,200); x0=(float)(r*cos (a))+dx ; //r=radius y0=(float)(- r*sin (a))+dy ; // Counterclockwise x1=(float)((r-100)*cos (a))+dx; //r=radius y1=(float)(- (r-100)*sin (a))+dy ; // counterclockwise cs.DrawLine (x1,y1, x0,y0); // Solid base color for (i= k[3]; i<=k[4] ; i++){// Draw surface color dx=360+15; dy=250 ; a=pi/360*i ; Cs. SetColor (255,0,200,250); x0=(float)(r*cos (a))+dx ; //r=radius y0=(float)(- r*sin (a))+dy ; // Counterclockwise x1=(float)((r-100)*cos (a))+dx; //r=radius y1=(float)(- (r-100)*sin (a))+dy ; // counterclockwise cs.DrawLine (x1,y1, x0,y0); Cs. SetColor (185200250250); DrawCircle (x0,y0,1.5); cs.DrawCircle (x1,y1,1.5); } // Face color a=pi/360*k[3]; x2=(float)(r*cos (a))+dx ; //r=radius y2=(float)(- r*sin (a))+dy ; // Counterclockwise a=pi/360*k[3]; x3=(float)((r-100)*cos (a))+dx ; //r=radius y3=(float)(- (r-100)*sin (a))+dy ; // Counterclockwise cs.SetColor(205,200,250,250); cs.DrawLine (x1,y1, x0,y0); DrawLine (x3,y3, x2,y2); // Drawline cs. drawline (x3,y3, x2,y2); // Add delimiter cs.SetColor(255,0,200,250); // Characters and % cs.DrawRect (80,4*30+90,140,4*30+115); //n=4 pn=p1[4]*10 ; // Reserve 1 decimal place pn=pn/1200; ss1=doubleToString (pn)+"%" ; ss2=intToString (p1[4]) ; Cs. SetColor (255250250, 0); cs.DrawText(ss2, 88,4*30+110); // Standard sample value cs.SetColor(255,250,250,250); // Plot superscript p1(n) 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) ; // Delay 1 second

The effect is as follows

Draw 2 or 3 blocks

dx=360 ; dy=280+4 ; for (t=1; t<=8 ; t++){// Bottom 16 line dy=dy-2; for (n=2; n<=3 ; n++){// Draw 1 and 3 color blocks for (i= k[n-1]; i<=k[n]; i++){ a=pi/360*i ; // a/2 draws a semicircle if (n==2) cs.SetColor(255,200,130,0); if (n==3) cs.SetColor(255,0,150,0); x0=(float)(r*cos (a))+dx ; //r=radius y0=(float)(- r*sin (a))+dy ; // Counterclockwise x1=(float)((r-100)*cos (a))+dx; //r=radius y1=(float)(- (r-100)*sin (a))+dy ; // counterclockwise cs.DrawLine (x1,y1, x0,y0); }}// Solid base for (n=2; n<=3 ; n++){// plus separator line a=pi/360*k[n]; x2=(float)(r*cos (a))+dx ; //r=radius y2=(float)(- r*sin (a))+dy ; // Counterclockwise a=pi/360*k[n]; x3=(float)((r-100)*cos (a))+dx ; //r=radius y3=(float)(- (r-100)*sin (a))+dy ; // Counterclockwise cs.SetColor(255,250,200,120); cs.DrawLine (x3,y3, x2,y2); }// separator}// t, cs.Update (); // Look at the middle effect sleep (1000);

The effect is as follows

Final effect

Finally draw the pie chart on the surface > Finished

for (n=2; n<=3 ; n++){ dy=280-16 ; for (i= k[n-1]; i<=k[n]; i++){ a=pi/360*i ; // a/2 draws a semicircle if (n==2) cs.SetColor(255,250,180,0); if (n==3) cs.SetColor(255,0,250,0); x0=(float)(r*cos (a))+dx ; //r=radius y0=(float)(- r*sin (a))+dy ; // Counterclockwise x1=(float)((r-100)*cos (a))+dx; //r=radius y1=(float)(- (r-100)*sin (a))+dy ; // counterclockwise cs.DrawLine (x1,y1, x0,y0); // Sector line cs.DrawRect (80,n*30+90,140,n*30+115); // cs.SetColor(205,250,230,150); DrawCircle (x0,y0,1.2); // Drawcircle (x0,y0,1.2); cs.DrawCircle (x1,y1,1.5); // Animation display line by line drawing additive color code pn=p1[n]*10; // Reserve 1 decimal place pn=pn/1200; ss1=doubleToString (pn)+"%" ; ss2=intToString (p1[n]) ; cs.DrawText(ss2, 88,n*30+110); // cs.SetColor(255,250,250,250); // Plot superscript p1(n) ma=pi/360*((k[n-1]+k[n])/2); x1=(float)((r-45)*cos (ma))+dx ; y1=(float)(-(r-45)*sin (ma))+dy ; cs.DrawText (ss1,x1-27,y1+5); // Tag cs.Update (); }} //show pie chart for (n=1; n<=3 ; n++){ a=pi/360*k[n] ; x2=(float)(r*cos (a))+dx ; //r=radius y2=(float)(- r*sin (a))+dy ; // Counterclockwise a=pi/360*k[n]; x3=(float)((r-100)*cos (a))+dx ; //r=radius y3=(float)(- (r-100)*sin (a))+dy ; // Counterclockwise cs.SetColor(245,250,250,150); cs.DrawLine (x3,y3, x2,y2); } // Add a dividing line // Tag: Art three-dimensional character production cs.SetFillMode (1); //0 without color filling, 1 with color filling cs.SetTextStyle (1); cs.SetStrokeWidth(1); cs.SetTextSize (28); Cs. SetColor (255,0,0,250); cs.DrawText ("Art Graphics 📊",480,60); cs.SetTextSize (46); ss=" Art Statistics Chart: three-dimensional ring chart "; Cs. SetColor (255,50,120,20); DrawText (ss,114,534); // Shadow cs.SetColor(255,0,250,0); cs.DrawText (ss,110,530); // cs.SetFillMode (0); //0 do not fill the color,1 fill the color cs.SetColor(255,250,150,0); cs.DrawText (ss,110,530); // Frame line cs.Update (); }//ArtGraphics4 () //**** END *****************

To this article about the use of C language to draw three-dimensional separation ring diagram is introduced to this, more related C language to draw three-dimensional ring diagram content please search script home previous articles or continue to browse the following related articles hope that you will support script home in the future!

Related article

Latest comments