很基础的教材,转载自:http://zedgraph.org/wiki/index.php?title=CSharp_Reference_Code_for_Sample_Charts
各种图表程序(C#、VB):http://zedgraph.org/wiki/index.php?title=Sample_Graphs
NOTE: The code on this page is for ZedGraph version 5. You can view the code for version 4.3 here.
The following is a step-by-step procedure to make a working ZedGraph chart using the ZedGraphControl. You can download a sample project that contains this entire tutorial here (Version 5.0.6).
Open Visual C# 2005 Express Edition (you can download it free here)From the File menu, select New ProjectSelect Windows Application, and name it ZedGraphSampleIn the Solution Explorer, right-click on References and select "Add Reference..."Pick the browse tab, and navigate to the zedGraph.dll (downloadable from here), and click OKFrom View menu, select Toolbox, scroll down to the bottom of the toolbox window to see the "General" barIf ZedGraphControl is not already available as an option, rightclick on the "General" bar, and select "Choose Items..."Under ".Net Framework Items" tab, click browseNavigate to the zedgraph.dll file, and click Open, Click OKIn the toolbox, left-click on the ZedGraphControl, go to your Form and click inside it to place a ZedGraphControl item.With the ZedGraphControl selected in the form, under the View menu select "Properties Window"Change the "(Name)" field for the ZedGraphControl to zg1 (it would typically be 'zedGraphControl1').Double click the Windows Form (not the ZedGraphControl), this will cause the window to switch to CodeView, with a template for the Form1_Load() methodGo to the top of the file and add using ZedGraph;Go to any sample graph from the ZedGraphWiki Sample section, and copy the entire contents of the CreateGraph() method into this new Code File (inside the Form1 class definition, but outside any existing method definition)Here's an example CreateGraph() method: private void CreateGraph( ZedGraphControl zgc ) { GraphPane myPane = zgc.GraphPane; // Set the titles and axis labels myPane.Title.Text = "My Test Date Graph"; myPane.XAxis.Title.Text = "X Value"; myPane.YAxis.Title.Text = "My Y Axis"; // Make up some data points from the Sine function PointPairList list = new PointPairList(); for ( double x = 0; x < 36; x++ ) { double y = Math.Sin( x * Math.PI / 15.0 ); list.Add( x, y ); } // Generate a blue curve with circle symbols, and "My Curve 2" in the legend LineItem myCurve = myPane.AddCurve( "My Curve", list, Color.Blue, SymbolType.Circle ); // Fill the area under the curve with a white-red gradient at 45 degrees myCurve.Line.Fill = new Fill( Color.White, Color.Red, 45F ); // Make the symbols opaque by filling them with white myCurve.Symbol.Fill = new Fill( Color.White ); // Fill the axis background with a color gradient myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45F ); // Fill the pane background with a color gradient myPane.Fill = new Fill( Color.White, Color.FromArgb(220, 220, 255), 45F ); // Calculate the Axis Scale Ranges zgc.AxisChange(); } The sample graph looks like this Go back to the design view, click on the Form (not the ZedGraphControl)From the View menu, select "Properties Window"At the top of the Properties window, click on the lightning bolt icon to see the eventsClick in the empty box to the right of "Resize", and hit enterYou will now be back in the code view, with a template for Form1_ResizeModify Form1_Resize, and add a SetSize() method to look like this: private void Form1_Resize( object sender, EventArgs e ) { SetSize(); } private void SetSize() { zg1.Location = new Point( 10, 10 ); // Leave a small margin around the outside of the control zg1.Size = new Size( this.ClientRectangle.Width - 20, this.ClientRectangle.Height - 20 ); } Modify your Form1_Load() method so that it looks like this: private void Form1_Load( object sender, EventArgs e ) { CreateGraph( zg1 ); SetSize(); }