/* Title: zedgraph's Web Application
* Author: alvinye
* Date: Aug 27,2006
* Description: Application of zedgraph on the Web
* Environment: WINXP SP2, vs2005 pro,. netframework 2.0
* Keyword: zedgraph's web application theme
*/
1. Create a new site
2. Reference zedgraph. Web. dll and zedgraph. dll
On www.zedgraph.org, you can download 3 to modify default2.aspx to the following content.
<% @ Page Language = "C #" codefile = "default2.aspx. cs" inherits = "default2" theme = "" %>
<% @ Register tagprefix = "zgw" namespace = "zedgraph. Web" assembly = "zedgraph. Web" %>
<Zgw: zedgraphweb id = "zedgraphweb1" runat = "server" width = "500" Height = "375" rendermode = "rawimage"/> note the theme = "" if you are on the web. if theme has been set in config, all pages will load theme first by default.
Because we only need to generate an image here. If theme is loaded, an error will be displayed. 4. Modify default. aspx. CS
Using system;
Using system. Drawing; using zedgraph;
Using zedgraph. Web;
Public partial class default2: system. Web. UI. Page
{
Protected void page_load (Object sender, system. eventargs E)
{
} # Region web form designer generated code
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base. oninit (E );
} // <Summary>
/// Required method for designer support-do not modify
/// The contents of this method with the code editor.
/// </Summary>
Private void initializecomponent ()
{
This. zedgraphweb1.rendergraph + = new zedgraph. Web. zedgraphwebcontroleventhandler (this. onrendergraph );}
# Endregion // <summary>
/// This method is where you generate your graph.
/// </Summary>
/// <Param name = "masterpane"> you are providing with a masterpane instance that
/// Contains one graphpane by default (accessible via masterpane [0]). </param>
/// <Param name = "G"> A graphics instance so you can easily make the call to axischange () </param>
Private void onrendergraph (system. Drawing. Graphics g, zedgraph. masterpane)
{
// Get the graphpane so we can work with it
Graphpane mypane = masterpane [0]; mypane. Title. Text = "";
Mypane. xaxis. Title. Text = "term ";
Mypane. yaxis. Title. Text = "score"; pointpairlist list = new pointpairlist ();
Pointpairlist list2 = new pointpairlist ();
Pointpairlist list3 = new pointpairlist (); datatable dt = builddt (); For (INT I = 0; I <DT. Rows. Count; I ++)
{
If (Dt. Rows [I] ["ID"]. tostring () = "1 ")
{
List. add (convert. todouble (DT. rows [I] ["Xueqi"]), convert. todouble (DT. rows [I] ["fenshu"]), "Alvin ");
}
Else if (Dt. Rows [I] ["ID"]. tostring () = "2 ")
{
List2.add (convert. todouble (DT. rows [I] ["Xueqi"]), convert. todouble (DT. rows [I] ["fenshu"]), "Robin ");
}
Else
{
List3.add (convert. todouble (DT. rows [I] ["Xueqi"]), convert. todouble (DT. rows [I] ["fenshu"]), "Jim ");
}
} Lineitem myline = mypane. addcurve ("Alvin", list, color. Red, symboltype. hdash );
Lineitem myline2 = mypane. addcurve ("Robin", list2, color. Green );
Lineitem myline3 = mypane. addcurve ("Jim", list3, color. Blue );
Masterpane. axischange (g );
} Private datatable builddt ()
{
Datatable dt = new datatable ("Students ");
DT. Columns. Add ("ID ");
DT. Columns. Add ("name ");
DT. Columns. Add ("Xueqi ");
DT. Columns. Add ("fenshu"); DT. Rows. Add (1, "Alvin", "1", 100 );
DT. Rows. Add (1, "Alvin", "2", 90 );
DT. Rows. Add (1, "Alvin", "3", 80 );
DT. Rows. Add (1, "Alvin", "4", 120 );
DT. Rows. Add (2, "Robin", "1", 120 );
DT. Rows. Add (2, "Robin", "1", 100 );
DT. Rows. Add (2, "Robin", "3", 90 );
DT. Rows. Add (2, "Robin", "4", 110 );
DT. Rows. Add (3, "Jim", "1", 80 );
DT. Rows. Add (3, "Jim", "2", 90 );
DT. Rows. Add (3, "Jim", "3", 130 );
DT. Rows. Add (3, "Jim", "4", 135); Return DT ;}
} The running result is as follows: