You need to make a statistical function. Of course, charts are the most intuitive choice. As for controls, if you want to use open-source components, you must first check the information on the Internet. There are quite a few examples of charts, zedgraph ,. net charts, nplot, xscharting, davechart, and nchart each have their own characteristics. My statistical function is relatively simple, so I have no specific choice to use it. I chose zedgraph directly.
First, create a pie chart and analyze the code.
Create a window application, introduce zedgraph DLL, place a zedgraphcontrol control on form, set its height and width, and add the following code, and call this method in form_load.
Public void createchart (zedgraphcontrol zgc)
{
Graphpane mypane = zgc. graphpane;
// Set the title and title style of the chart.
Mypane. Title. Text = "2004 zedgraph sales by region \ n ($ m )";
Mypane. Title. fontspec. isitalic = true;
Mypane. Title. fontspec. size = 24f;
Mypane. Title. fontspec. Family = "Times New Roman ";
// Set the background color
Mypane. Fill = New fill (color. White, color. goldenrod, 45.0f );
// Set the color fill of the chart. If it is set to filltype. None, the fill color is the same as the background color.
Mypane. Chart. Fill. type = filltype. None;
// Set the legend size and position
Mypane. Legend. Position = legendpos. Float;
Mypane. Legend. Location = new location (0.95f, 0.15f, coordtype. panefraction,
Alignh. Right, alignv. Top );
Mypane. Legend. fontspec. size = 10f;
Mypane. Legend. ishstack = false;
/*
* Set the parts of a pie chart
* The parameters of addpieslice are value, color, gradient, gradient size, distance from the center, and name.
*/
Pieitem segment1 = mypane. addpieslice (20, color. Navy, color. White, 45f, 0, "North ");
Pieitem segment3 = mypane. addpieslice (30, color. Purple, color. White, 45f, 0, "East ");
Pieitem segment4 = mypane. addpieslice (10.21, color. limegreen, color. White, 45f, 0, "West ");
Pieitem segment2 = mypane. addpieslice (40, color. sandybrown, color. White, 45f, 0.2, "South ");
Pieitem segment6 = mypane. addpieslice (250, color. Red, color. White, 45f, 0, "Europe ");
Pieitem segment7 = mypane. addpieslice (50, color. Blue, color. White, 45f, 0.2, "Pac rim ");
Pieitem segment8 = mypane. addpieslice (400, color. Green, color. White, 45f, 0, "South America ");
Pieitem segment9 = mypane. addpieslice (50, color. Yellow, color. White, 45f, 0.2, "Africa ");
Zgc. axischange ();
}
Okay, run it directly and a simple pie chart will appear.
Technorati: Using zedgraph as a chart