C # create a three-dimensional pie chart (cool)

Source: Internet
Author: User

Address: http://www.msproject.cn/Article/3DTransparentPie.html

 

[Translation]
Julijan sribar with 3D pie chart

A c # class library used to draw a three-dimensional pie chart

[Introduction]

The idea of this article is to create an independent class library that can be used to draw three-dimensional pie charts. First, it looks very simple, because there is a method called drawpie in the graphics class. This method receives the starting angle and expanding angle as parameters, so it does not seem to have any other problems. However, it implements a flat pie chart and I need a three-dimensional perspective chart. If you need such a control, this article will be no longer suitable.


[Code usage]

The piechart solution in this article includes three classes: pieslice, piechart3d, and piechartcontrol (inherited from system. Windows. Forms. panel controls ). The pieslice class provides the ability to draw a 3-D pie chart. You can set its starting, expanding angle, color, height, and shadow type.

The piechart3d class represents the entire graph. There are several constructors worth noting that they can receive the following values:

Color value Array
Slice displacement (displacement) array
Slice thickness

Because the displacement is represented by the "depth" ratio of the slice and the elliptical radius, the minimum value 0 indicates no displacement, and the maximum value 1 indicates that the shape occupies the entire ellipse.

The slice thickness also represents a ratio (relative to the vertical distance of the elliptic), and the maximum allowed value is 0.5.

Of course, you can also set the above value through a public function. Note: If the number of colors set is less than the number of slices, the color will be reused. Similarly, if displacement does not exist, the last value will be reused.

Configurable public attributes are as follows:
* Texts,
* Font,
* Forecolor,
* Shadowstyle,
* Edgecolortype,
* Edgelinewidth,
* Initialangle,
* Fittoboundingrectangle.

Through the demonstration program of the article, you can easily understand the meaning of each attribute.

The piechart3d class can also be usedPrint, Initialize the object, and then call its draw method (provide a corresponding graphics object ).

public void Draw(Graphics graphics) { ... }

If you want to display the image on the screen, you can use piechartcontrol; it encapsulates the function of graphics to the Panel. You only need to put it on the form, and then set the desired attribute to OK. For example:

private System.Drawing.PieChart.PieChartControl panelDrawing =new System.Drawing.PieChart.PieChartControl();panelDrawing.Values = new decimal[] { 10, 15, 5, 35};int alpha = 80;panelDrawing.Colors = new Color[] { Color.FromArgb(alpha, Color.Red),Color.FromArgb(alpha, Color.Green),Color.FromArgb(alpha, Color.Yellow),Color.FromArgb(alpha, Color.Blue) };panelDrawing.SliceRelativeDisplacements = new float[] { 0.1F, 0.2F, 0.2F, 0.2F };panelDrawing.Texts = new string[] { "red","green","blue","yellow" };panelDrawing.ToolTips = new string[] { "Peter","Paul","Mary","Brian" };panelDrawing.Font = new Font("Arial", 10F);panelDrawing.ForeColor = SystemColors.WindowTextpanelDrawing.LeftMargin = 10F;panelDrawing.RightMargin = 10F;panelDrawing.TopMargin = 10F;panelDrawing.BottomMargin = 10F;panelDrawing.SliceRelativeHeight = 0.25F;panelDrawing.InitialAngle = -90F;

The piechartcontrol class overrides the onpaint and onresize events, which allow correct pie chart repainting tasks.

Note: The piechartcontrol class also has a tooltips attribute, which is used to give the corresponding tip when you move your mouse over a slice. If this array is not set, the value corresponding to the slice is displayed.

3dpiechart.rar 3dpiechart_vs2005.rar

 

Related Article

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.