Simple Application of zedgraph in Asp.net

Source: Internet
Author: User
First, the project references Zedgraph. dll and Zedgraph. Web. dll
And added
Graph

The ASPX page code is as follows:
<% @ Page Language = "C #" codebehind = "cookepic. aspx. cs" autoeventwireup = "false" inherits = "ws. webs. cookepic" %>
<% @ Register tagprefix = "PC3" namespace = "zedgraph. Web" assembly = "zedgraph. Web" %>
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> cookepic </title>
<Meta name = "generator" content = "Microsoft Visual Studio. NET 7.1">
<Meta name = "code_language" content = "C #">
<Meta name = "vs_defaultclientscript" content = "JavaScript">
<Meta name = "vs_targetschema" content = "http://schemas.microsoft.com/intellisense/ie5">
</Head>
<Body ms_positioning = "gridlayout">
<Form ID = "form1" method = "Post" runat = "server">
<PC3: zedgraphweb id = "zedgraphweb1" runat = "server"> </PC3: zedgraphweb>
</Form>
</Body>
</Html>

Key code of the Aspx. CS page

// Reference
Using zedgraph;
Using zedgraph. Web;

Private void initializecomponent ()
{
This. Load + = new system. eventhandler (this. page_load );
This. zedgraphweb1.rendergraph + = new zedgraphwebcontroleventhandler (this. onrendergraph );
}

Private void onrendergraph (zedgraph. Web. zedgraphweb webobject, system. Drawing. Graphics g, zedgraph. masterpane)
{
Datatable dt = new datatable ();

Datacolumn col0 = new datacolumn ("stock name ");
Datacolumn col1 = new datacolumn ("January ");
Datacolumn col2 = new datacolumn ("February ");
Datacolumn col3 = new datacolumn ("March ");
Datacolumn col4 = new datacolumn ("April ");
Datacolumn col5 = new datacolumn ("May ");
Datacolumn col6 = new datacolumn ("June ");
Datacolumn col7 = new datacolumn ("July ");
Datacolumn col8 = new datacolumn ("August ");
Datacolumn col9 = new datacolumn ("September ");
Datacolumn col10 = new datacolumn ("October ");
Datacolumn col11 = new datacolumn ("November ");
Datacolumn col12 = new datacolumn ("December ");

DT. Columns. Add (col0 );
DT. Columns. Add (col1 );
DT. Columns. Add (col2 );
DT. Columns. Add (col3 );
DT. Columns. Add (col4 );
DT. Columns. Add (col5 );
DT. Columns. Add (col6 );
DT. Columns. Add (col7 );
DT. Columns. Add (col8 );
DT. Columns. Add (col9 );
DT. Columns. Add (col10 );
DT. Columns. Add (col11 );
DT. Columns. Add (col12 );

Datarow row1 = DT. newrow ();
Row1 [0] = "Vanke ";
Row1 [1] = "10.5 ";
Row1 [2] = "11.9 ";
Row1 [3] = "12.8 ";
Row1 [4] = "15 ";
Row1 [5] = "13.5 ";
Row1 [6] = "15.5 ";
Row1 [7] = "17 ";
Row1 [8] = "19 ";
Row1 [9] = "20.5 ";
Row1 [10] = "25 ";
Row1 [11] = "29.5 ";
Row1 [12] = "30 ";
DT. Rows. Add (row1 );

Datarow row2 = DT. newrow ();
Row2 [0] = "chengkai ";
Row2 [1] = "18 ";
Row2 [2] = "19.5 ";
Row2 [3] = "16.9 ";
Row2 [4] = "13.2 ";
Row2 [5] = "11.9 ";
Row2 [6] = "10 ";
Row2 [7] = "13 ";
Row2 [8] = "15.6 ";
Row2 [9] = "18.2 ";
Row2 [10] = "16.6 ";
Row2 [11] = "11.5 ";
Row2 [12] = "9 ";
DT. Rows. Add (row2 );


Graphpane mypane = masterpane [0];

Mypane. Title. Text = "stock trend chart ";
Mypane. xaxis. Title. Text = "month ";
Mypane. yaxis. Title. Text = "price ";

// Create two curves
Pointpairlist list1 = new pointpairlist ();
Pointpairlist list2 = new pointpairlist ();
For (INT I = 1; I <DT. Columns. Count; I ++)
{
Double Y1 = double. parse (Dt. Rows [0] [I]. tostring ());
Double y2 = double. parse (Dt. Rows [1] [I]. tostring ());
Int x = I;

List1.add (x, Y1 );
List2.add (x, Y2 );
}


Lineitem mycurve2 = mypane. addcurve ("chengkai", list1, color. Blue, symboltype. Circle); // Add a new curve

// Mycurve2.line. Fill = New fill (color. White, color. Red, 45f); // fill the space under the curve

Mycurve2.symbol. Fill = New fill (color. White); // fill in the symbolic color on the curve


Lineitem mycurve1 = mypane. addcurve ("Vanke", list2, color. mediumvioletred, symboltype. Diamond );
Mycurve1.symbol. Fill = New fill (color. White );

String [] labels = new string [DT. Columns. Count-1];
// Add instructions to each interval on the X axis
For (INT I = 0; I <DT. Columns. Count-1; I ++)
{
String colname = DT. Columns [I + 1]. columnname. tostring ();
Labels [I] = colname;
}

Mypane. xaxis. Scale. textlabels = labels; // The textlabels attribute is set here, so the type of the X axis below must also be set to text

// Set the x-axis Style
Mypane. xaxis. type = axistype. text;

Mypane. xaxis. crossauto = true;

Mypane. Chart. Fill = New fill (color. White, color. lightgoldenrodyellow, 45f); // fill the axis background with a color gradient

Masterpane. axischange (g );
}

The final result is as follows:

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.