Graph report for netcf Development

Source: Internet
Author: User
Drawing graphical reports

You can also use the. NET Compact Framework rendering function to draw graphical reports, such as pie charts, column charts, or line charts. The following uses a pie chart as an example to describe how to create a pie chart. The code for creating a pie chart is shown in listing 7-8.

 

Listing 7-8: creating a pie chart



......

Dim CBMP as new Bitmap (236,184) 'create a bitmap instance with a canvas width of 236 and a height of 184

Dim cgraphic as graphics

Dim ccolor () as color = {color. Red, color. Blue, color. Green, color. Gray ,_

Color. lightcoral, color. Gold} '5 colors

Dim cpen as pen

Dim csolidbrush as solidbrush

Dim cpoints () as point

Dim rownum as integer = 3' defines the number of slice Blocks

Dim I as integer = 0

Dim J as integer = 0

Dim cangle as integer = 0

Dim TMP as integer = 0

Dim xcirclecenter as integer = 100 'defines the center X coordinate

Dim ycirclecenter as integer = 100 'defines the Y coordinate of the center

Cgraphic = graphics. fromimage (CBMP)

Cgraphic. Clear (color. Snow)

For J = 0 to rownum

Cangle = 90' defines the slice Angle

Redim cpoints (cangle + 1)

'Draw circles with mathematical formulas

Cpen = new pen (ccolor (J), 3)

Csolidbrush = new solidbrush (ccolor (j ))

For I = TMP to TMP + cangle

Cpoints (I-TMP) = new point

Cpoints (I-TMP). x = (1-system. Math. Sin (I/360*2 * system. Math. Pi) * (xcirclecenter-30) + 10

Cpoints (I-TMP). Y = (1-system. Math. Cos (I/360*2 * system. Math. Pi) * (ycirclecenter-30) + 10

Next I

'Add the coordinate point of the center

Cpoints (cangle + 1) = new point

Cpoints (cangle + 1). x = xcirclecenter-20

Cpoints (cangle + 1). Y = ycirclecenter-20

'Area of the slice to be drawn

Cpen = new pen (ccolor (J), 3)

Csolidbrush = new solidbrush (ccolor (j ))

Cgraphic. drawpolygon (cpen, cpoints)

Cgraphic. fillpolygon (csolidbrush, cpoints)

TMP = TMP + cangle

Next

Pb_graphic.image = CBMP

......

 

In listing 7-8, a canvas of the specified size is first defined, and the canvas is also a bitmap instance. Then define the coordinates of the center. To determine the coordinates of the center point, you can use the calculation formula to obtain a set of points that constitute the arc of each slice. The set of arc points and the center point form a closed sector area. After determining the slice area, you can start to draw a slice chart and fill the slice area with different colors. Finally, the drawn bitmap instance is displayed through the picturebox control. The execution result of listing 7-8 is 7-6.

 

Figure 7-6: Pie Chart

With the same principle, you can also implement a bar chart, as shown in 7-7.

Figure 7-7: bar chart

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.